Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'd like to use NUnit to run unit tests in my plug-in, but it needs to be run in the context of my application. To solve this, I was trying to develop a plug-in that runs NUnit, which in turn will execute my tests in the application's context.

I didn't find a specific documentation on this subject so I dug a piece of information here and there and I came out with the following piece of code (which is similar to one I found here in StackOverflow):

    public static void Main()
    {
        SimpleTestRunner runner = new SimpleTestRunner();
        TestPackage package = new TestPackage( "Test" );
        string loc = Assembly.GetExecutingAssembly().Location
        package.Assemblies.Add( loc );
        if( runner.Load(package) )
        {
            TestResult result = runner.Run( new NullListener() );
        }
    }

The result variable says "has no TestFixture" although I know for sure it is there. In fact my test file contains two test.

Using another approach I found, which is summarized by the following code:

TestSuiteBuilder builder = new TestSuiteBuilder();
TestSuite testSuite = builder.Build( package );

// Run tests
TestResult result = testSuite.Run( new NullListener(), NUnit.Core.TestFilter.Empty );

I saw nunit data structures with only 1 test and I had the same error.

For sake of completeness, I am using the latest version of nunit, which is 2.5.5.10112.

Does anyone know what I'm missing? A sample code would be appreciated. My test class is:

[TestFixture]
public class UnitTests
{
    public UnitTests()
    {
    }

    [Test]
    public void TestEqual()
    {
        long a = 10;
        long b = 10;
        Assert.AreEqual( a, b );
    }

    [Test]
    public void TestNotEqual()
    {
        long a = 10;
        long b = 11;
        Assert.AreNotEqual( a, b );
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
146 views
Welcome To Ask or Share your Answers For Others

1 Answer

The below code help to resolve the issue

public static void Main()
{
    CoreExtensions.Host.InitializeService();
    SimpleTestRunner runner = new SimpleTestRunner();
    TestPackage package = new TestPackage( "Test" );
    string loc = Assembly.GetExecutingAssembly().Location;
    package.Assemblies.Add( loc );
    if( runner.Load(package) )
    {
        TestResult result = runner.Run( new NullListener(),
            TestFilter.Empty, false, LoggingThreshold.Off );
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...