如何以编程方式使用Gallio和MBUnit运行单元测试? [英] How to programmatically run unit tests with Gallio and MBUnit?

查看:151
本文介绍了如何以编程方式使用Gallio和MBUnit运行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式检查单元测试是否通过,这是部署过程的一部分.该应用程序使用MBunit和Gallio作为其单元测试框架.

I'm trying to programmatically check my unit tests are passing as part of my deployment process. The application uses MBunit and Gallio for it's unit testing framework.

这是我的代码:

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中包含的测试(我已经验证了它可以与Icarus测试运行器一起使用):

Here's the test which is contained in the DLL I'm loading (I've validated this works with the Icarus test runner):

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

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

运行应用程序时,我在results

When I run the application I get the following values in results

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

Which is incorrect as there are indeed tests to run! The log file has the following in it

禁用的插件'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".

Disabled plugin 'Gallio.VisualStudio.Shell90': The plugin enable condition was not satisfied. Please note that this is the intended behavior for plugins that must be hosted inside third party applications in order to work. Enable condition: '${process:DEVENV.EXE_V9.0} or ${process:VSTESTHOST.EXE_V9.0} or ${process:MSTEST.EXE_V9.0} or ${framework:NET35}'. Disabled plugin 'Gallio.VisualStudio.Tip90': The plugin depends on another disabled plugin: 'Gallio.VisualStudio.Shell90'.

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

How do I resolve this issue and find the results to the tests?

推荐答案

这对我有用,请注意我使用了

This works for me, note I used this GallioBundle nuget to get gallio and mbunit, so perhaps there is some difference to what you have installed.

有关插件的日志消息是预期的,如果您是自托管Gallio运行时,则这些插件将无法工作.

The log messages regarding plugins are expected, those plugins wont work if you are self-hosting the Gallio runtime.

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

这篇关于如何以编程方式使用Gallio和MBUnit运行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆