gpt4 book ai didi

c# - 如何使用 Gallio 和 MBUnit 以编程方式运行单元测试?

转载 作者:太空狗 更新时间:2023-10-29 20:30:46 26 4
gpt4 key购买 nike

我正在尝试以编程方式检查我的单元测试是否作为部署过程的一部分通过。该应用程序使用 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

中得到以下值

enter image description here

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

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'.

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

最佳答案

这对我有用,请注意我使用了这个 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

关于c# - 如何使用 Gallio 和 MBUnit 以编程方式运行单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21044212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com