2014-01-10 45 views
7

我试图以编程方式检查我的单元测试是否作为我的部署过程的一部分传递。该应用程序使用MBunit和Gallio作为单元测试框架。如何以编程方式使用Gallio和MBUnit运行单元测试?

这里是我的代码:

var setup = new Gallio.Runtime.RuntimeSetup(); 
setup.AddPluginDirectory(@"C:\Program Files\Gallio\bin"); 

using (TextWriter tw = new StreamWriter(logFilename)) 
{ 
    var logger = new Gallio.Runtime.Logging.TextLogger(tw); 
    RuntimeBootstrap.Initialize(setup, logger); 

    TestLauncher launcher = new TestLauncher();     
    launcher.AddFilePattern(dllToRunFilename); 
    TestLauncherResult result = launcher.Run(); 
} 

这里是它包含在我加载(我已经验证了这种工作原理与伊卡洛斯测试运行器)的DLL测试:

public class Tests 
    { 
     [Test] 
     public void Pass() 
     {    
      Assert.IsTrue(true); 
     } 

     [Test] 
     public void Fail() 
     { 
      Assert.Fail(); 
     } 
    } 

当我运行应用程序,我得到以下值results

enter image description here

这是不正确的,因为确实有测试运行!日志文件有以下内容

已禁用插件“Gallio.VisualStudio.Shell90”:插件启用 条件未得到满足。请注意,这是为了工作而必须在第三方 应用程序中托管的插件的预期 行为。启用条件: '$ {process:DEVENV.EXE_V9.0}或$ {process:VSTESTHOST.EXE_V9.0}或 $ {process:MSTEST.EXE_V9.0}或$ {framework:NET35}'。禁用插件 'Gallio.VisualStudio.Tip90':该插件取决于另一个禁用的 插件:'Gallio.VisualStudio.Shell90'。

如何解决此问题并找到测试结果?

+0

什么版本的Visual Studio? – jessehouwing

+0

我正在VS2012 – Liath

+1

我之前没有与Gallio一起工作过,所以我不确定这是否有问题,但您的'Tests'类不是'[TestFixture]'。也许Gallio没有看到“[Test]”,因为它找不到灯具。 – Caleb

回答

4

这适用于我,请注意我用这个GallioBundle nuget来获得gallio和mbunit,所以也许你的安装有些不同。

预期有关插件的日志消息,如果您自承载Gallio运行时,那些插件将无法正常工作。

using System; 
using System.IO; 
using Gallio.Runner; 
using Gallio.Runtime; 
using Gallio.Runtime.Logging; 
using MbUnit.Framework; 

public static class Program 
{ 
    public static void Main() 
    { 
     using (TextWriter tw = new StreamWriter("RunTests.log")) 
     { 
      var logger = new TextLogger(tw); 
      RuntimeBootstrap.Initialize(new RuntimeSetup(), logger); 

      TestLauncher launcher = new TestLauncher(); 
      launcher.AddFilePattern("RunTests.exe"); 
      TestLauncherResult result = launcher.Run(); 
      Console.WriteLine(result.ResultSummary); 
     } 
    } 
} 

public class Tests 
{ 
    [Test] 
    public void Pass() 
    { 
     Assert.IsTrue(true); 
    } 

    [Test] 
    public void Fail() 
    { 
     Assert.Fail(); 
    } 
} 

测试是这样的:

› notepad RunTests.cs 
› nuget.exe install -excludeversion GallioBundle 
    Installing 'GallioBundle 3.4.14.0'. 
    Successfully installed 'GallioBundle 3.4.14.0'. 
› cd .\GallioBundle\bin 
› csc ..\..\RunTests.cs /r:Gallio.dll /r:MbUnit.dll 
    Microsoft (R) Visual C# Compiler version 12.0.21005.1 
    for C# 5 
    Copyright (C) Microsoft Corporation. All rights reserved.  
› .\RunTests.exe 
    2 run, 1 passed, 1 failed, 0 inconclusive, 0 skipped 
+0

我不害怕 - 我已经从他们的网站获得了Gallio和MBUnit,但是我得到了“无法解析服务类型的组件Gallio.Runner.Projects.ITestProjectManager',因为没有出现任何组件注册并启用该服务类型“。 – Liath

+0

我实际上设法以编程方式运行我很乐意使用的NUnit测试,所以不要惊慌太多。 – Liath

+0

我已经将此标记为答案,因为尽管我无法使其工作,但它与我见过的其他文档相匹配,并且OP提供了一个完整示例 – Liath

0

这些是在Visual Studio 2012上运行MbUnit的测试和使用上面整齐NUnit的伎俩指令。

首先,安装NUnit测试适配器扩展(是的,NUnit的)

  • 工具>扩展和更新>在线>搜索NUnit的>安装 NUnit测试适配器。
  • 您可能需要重新启动Visual Studio IDE。

然后,你只需要添加一个新的NUnit测试属性到你的测试方法。见示例代码这里(注意using语句在顶部)...

//C# example 
using MbUnit.Framework; 
using NuTest = NUnit.Framework.TestAttribute; 

namespace MyTests 
{ 
    [TestFixture] 
    public class UnitTest1 
    { 
     [Test, NuTest] 
     public void myTest() 
     { 
      //this will pass 
     } 
    } 
} 

可以运行和调试在Visual Studio在NUnit和加利奥伊卡洛斯GUI测试运行测试将运行它们的MbUnit的(启用并行运行例如)。您需要停止Gallio运行NUnit测试,方法是删除安装位置中的NUnit文件夹,即C:\ Program Files \ Gallio \ bin \ NUnit

相关问题