C# 无法以编程方式成功运行NUnit

C# 无法以编程方式成功运行NUnit,c#,nunit,C#,Nunit,我目前正在尝试以编程方式运行测试,我有两个解决方案,一个是包含测试的类库,另一个是控制台应用程序。 我想从控制台应用程序运行DLL(类库输出)中包含的测试 下面是类库的代码 [TestFixture] public class TestClass { [Test] public void TestMethod() { // TODO: Add your test code here Assert.IsTrue(true); }

我目前正在尝试以编程方式运行测试,我有两个解决方案,一个是包含测试的类库,另一个是控制台应用程序。 我想从控制台应用程序运行DLL(类库输出)中包含的测试

下面是类库的代码

[TestFixture]
public class TestClass
{
    [Test]
    public void TestMethod()
    {
        // TODO: Add your test code here
        Assert.IsTrue(true);
    }

    [Test]
    public void Test()
    {
        // TODO: Add your test code here
        Assert.IsTrue(true);
    }
}
这是我的控制台应用程序代码

static void Main(string[] args)
{          
    TestPackage testPackage = new TestPackage("Test");
    testPackage.Assemblies.Add(
           @"C:\DEV\NUnitConsole\NUnit.Tests\bin\Debug\NUnit.Tests.dll");

    RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
    remoteTestRunner.Load(testPackage);
    TestResult result = remoteTestRunner.Run(new NullListener(),
             TestFilter.Empty, false, LoggingThreshold.Error);

    Console.ReadLine();
}
一切运行顺利,但我从来没有得到一个结果的测试,它只是说,这是不确定的

{NUnit.Core.TestResult}
资产计数:0
描述:空
执行:正确
失败地点:测试
全名:“C:\\DEV\\NUnitConsole\\NUnit.Tests\\bin\\Debug\\NUnit.Tests.dll”
结果:错误
伊瑟罗:错
IsFailure:false
IsSuccess:错误
消息:空
名称:“C:\\DEV\\NUnitConsole\\NUnit.Tests\\bin\\Debug\\NUnit.Tests.dll”
结果:无定论
结果:空
StackTrace:null
测试:{NUnit.Core.TestInfo}
时间:0.0012101472641609884

您是否尝试过使用
nunit3 console.exe
?您可以使用参数执行,例如:

nunit3-console.exe "TestNunit.dll" -noresult
您可以在以下位置找到
nunit3 console.exe

C:\Users\xxxxxx\Documents\Visual Studio 20xx\Projects\\packages\NUnit.ConsoleRunner.3.7.0\tools


使用nuget
NUnit.ConsoleRunner安装后
您是否尝试过使用
nunit3 console.exe
?您可以使用参数执行,例如:

nunit3-console.exe "TestNunit.dll" -noresult
您可以在以下位置找到
nunit3 console.exe

C:\Users\xxxxxx\Documents\Visual Studio 20xx\Projects\\packages\NUnit.ConsoleRunner.3.7.0\tools


在使用nuget
NUnit.ConsoleRunner安装后,我尝试了同样的方法-它似乎起到了作用:根据测试结果,我得到的结果状态为“成功”或“失败”。您使用的是什么版本的Nunit?也许您的代码中还有其他原因导致了这个问题?我也尝试过同样的方法——它似乎起到了作用:根据测试结果,我得到的结果状态为“成功”或“失败”。您使用的是什么版本的Nunit?也许你的代码中还有其他东西造成了这个问题?