简体   繁体   中英

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

Below the Code of the 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 ? You can execute with arguments, for example:

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

You can find nunit3-console.exe in:

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

After installing with nuget NUnit.ConsoleRunner .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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