8

注意:我在这个项目中使用 TestDriven.NET 3.0.2749 和 NUnit 2.6.0.12051。

我已经安装了 TestDriven.NET 和 NUnit,并试图让 TestDriven.NET 通过右键单击上下文菜单运行测试类中的所有测试。

从 TestDriven.NET 文档:

如果选择了代码编辑器窗口,则要执行的测试将由插入符号的位置决定;通过右键单击测试方法内的任意位置并选择“运行测试”来执行单个测试,如图 2 所示;测试夹具中的所有测试都是通过在类内部(但在任何方法之外)右键单击并选择“运行测试”来执行的;命名空间中的所有测试都是通过在命名空间内右键单击并选择“运行测试”来执行的。

我可以使用右键单击上下文菜单成功运行特定的测试方法,并且 NUnit GUI 运行程序将成功运行给定类的所有测试,但我想使用 TestDriven.NET 为这个任务提供的快速访问,而我发展。

当我将插入符号放在测试方法之外时,我收到以下错误:

目标类型不包含来自已知测试框架或“主要”方法的测试。

更新 1:添加了示例代码。

要测试的示例代码:

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

单元测试:

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

2 回答 2

16

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.

于 2012-07-12T19:07:55.613 回答
0

我在插入符号位置上有完全相同的错误消息和类似的行为。

我已经拥有了最新版本的 TestDriven.Net。

我的问题是我的新 TestClass 没有指定类别并且它被过滤掉了(工具 -> TestDriven.Net -> 常规 -> 类别 -> 在类别中包含测试)。

因此,只需指定正确的类别即可解决我的问题。

这是相同的错误消息,但不同的问题和解决方案。

于 2013-05-29T12:06:47.380 回答