Frage

Note: I am using TestDriven.NET 3.0.2749 and NUnit 2.6.0.12051 for this project.

I have installed both TestDriven.NET and NUnit and am trying to get TestDriven.NET to run all tests in a test class via the right-click context menu.

From the TestDriven.NET documentation:

If the code editor window is selected, the test(s) to execute will be determined by the position of the caret; individual tests are executed by right-clicking anywhere inside a test method and selecting 'Run Test(s)' as shown in Figure 2; all tests in a test fixture are executed by right-clicking inside a class (but outside of any method) and selecting 'Run Test(s)'; all tests in a namespace are executed by right-clicking inside a namespace and selecting 'Run Test(s)'.

I can successfully run a specific test method using the right-click context menu and the NUnit GUI runner will successfully run all test for a given class, but I would like to use the quick access TestDriven.NET provides for this tasks while I'm developing.

I receive the follow error when I place the caret outside of test method:

The target type doesn't contain tests from a known test framework or a 'Main' method.

Updated 1: Added example code.

Example code to test:

namespace TDDN.Framework
{
    public class ExampleClass
    {
        public ExampleClass() { }

        public Int32 Add(Int32 x, Int32 y)
        {
            return x + y;
        }

        public Int32 Subtract(Int32 x, Int32 y)
        {
            return x - y;
        }
    }
}

Unit tests:

using NUnit.Framework;
using TDDN.Framework;

namespace TDDN.UnitTests
{
    [TestFixture] // Cursor caret placed here results in error above.
    public class ExampleClassTests
    {
        [Test] // Cursor caret placed here works.
        public void Add_SumTwoIntegers_SumReturned()
        {
            ExampleClass exampleClass = new ExampleClass();

            Assert.AreEqual(10, exampleClass.Add(5, 5));
        }

        [Test] // Cursor caret placed here works also.
        public void Subtract_SubtractTwoIntegers_DifferenceReturned()
        {
            ExampleClass exampleClass = new ExampleClass();

            Assert.AreEqual(5, exampleClass.Subtract(10, 5));
        }
    }
}
War es hilfreich?

Lösung

I just encountered this exact problem when using the same versions of TestDriven.NET and NUnit (3.0.2749 and 2.6.0.12051).

The issue is that TestDriven.NET 3.0 doesn't support NUnit 2.6, so it won't recognize the NUnit [Test] and [TestFixture] attributes. Thus, TestDriven.NET will still run your individual test functions, but as Ad Hoc (as displayed at the end of the Pass/Fail/Skip message when testing).

I was able to solve the issue by installing a newer version of TestDriven.NET (3.3 Beta 2), which fully supports NUnit 2.6 (See: https://groups.google.com/d/msg/nunit-discuss/pTCDx2_L8jU/TlpULzE36wEJ) Now you should be able to run all the tests in the fixture at once and see (NUnit 2.6.0) displayed at the end of the test output.

Andere Tipps

I had exactly the same error message and similar behaviour on the caret placements.

I already had the newest version of TestDriven.Net.

My problem was that my new TestClass did not have a Category specified and it was filtered out (Tools -> TestDriven.Net -> General -> Categories -> Include tests in categories).

So just specifying the correct Category fixed my problem.

It was the same error message, but a different problem and solution.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top