简体   繁体   English

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

[英]Unable to successfully run NUnit programmatically

I'm currently trying to run tests programmatically, I have two solutions, one is a class library containing the tests and the other one is a console application. 我目前正在尝试以编程方式运行测试,我有两个解决方案,一个是包含测试的类库,另一个是控制台应用程序。 I want to run the tests contained in the DLL (the class library output) from the Console Application 我想从控制台应用程序运行DLL(类库输出)中包含的测试

Below the Code of the ClassLibrary 在ClassLibrary的代码下面

[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);
    }
}

And this is my Console Application code 这是我的控制台应用程序代码

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();
}

Everything runs successfully however I never get a result of the test, it just says that is inconclusive. 一切都运行成功,但我从来没有得到测试的结果,它只是说这是不确定的。

{NUnit.Core.TestResult}
AssertCount: 0
Description: null
Executed: true
FailureSite: Test
FullName: "C:\\DEV\\NUnitConsole\\NUnit.Tests\\bin\\Debug\\NUnit.Tests.dll"
HasResults: false
IsError: false
IsFailure: false
IsSuccess: false
Message: null
Name: "C:\\DEV\\NUnitConsole\\NUnit.Tests\\bin\\Debug\\NUnit.Tests.dll"
ResultState: Inconclusive
Results: null
StackTrace: null
Test: {NUnit.Core.TestInfo}
Time: 0.0012101472641609884

Have you tried with nunit3-console.exe ? 你试过nunit3-console.exe吗? You can execute with arguments, for example: 您可以使用参数执行,例如:

nunit3-console.exe "TestNunit.dll" -noresult

You can find nunit3-console.exe in: 你可以找到nunit3-console.exe

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

After installing with nuget NUnit.ConsoleRunner . 用nuget NUnit.ConsoleRunner安装后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM