作为部署过程的一部分,我正在尝试以编程方式检查我的单元测试是否通过。该应用程序使用 MBunit 和 Gallio 作为其单元测试框架。
这是我的代码:
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 测试运行程序配合使用):
public class Tests
{
[Test]
public void Pass()
{
Assert.IsTrue(true);
}
[Test]
public void Fail()
{
Assert.Fail();
}
}
当我运行该应用程序时,我得到以下值results
这是不正确的,因为确实需要运行测试!日志文件中有以下内容
禁用插件“Gallio.VisualStudio.Shell90”:插件启用
条件不满足。请注意,这是预期的
必须托管在第三方内部的插件的行为
应用程序才能工作。启用条件:
'${process:DEVENV.EXE_V9.0} 或 ${process:VSSTESTHOST.EXE_V9.0} 或
${process:MSTEST.EXE_V9.0} 或 ${framework:NET35}'。禁用插件
“Gallio.VisualStudio.Tip90”:该插件依赖于另一个已禁用的插件
插件:“Gallio.VisualStudio.Shell90”。
如何解决此问题并找到测试结果?
这对我有用,请注意我用过这个加里奥捆绑包 http://www.nuget.org/packages/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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)