使用 TestDriven.NET 和 NUnit 在测试类中运行所有测试 [英] Run all tests in a test class using TestDriven.NET and NUnit

查看:60
本文介绍了使用 TestDriven.NET 和 NUnit 在测试类中运行所有测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

来自 TestDriven.NET 文档:

From the TestDriven.NET documentation:

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

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)'.

我可以使用右键单击上下文菜单成功运行特定的测试方法,并且 NUnit GUI 运行器将成功运行给定类的所有测试,但我想使用 TestDriven.NET 为该任务提供的快速访问我正在开发中.

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:

目标类型不包含来自已知测试框架或Main"方法的测试.

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

更新 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));
        }
    }
}

推荐答案

我刚刚在使用相同版本的 TestDriven.NET 和 NUnit(3.0.2749 和 2.6.0.12051)时遇到了这个确切的问题.

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

问题在于 TestDriven.NET 3.0 不支持 NUnit 2.6,因此它无法识别 NUnit [Test] 和 [TestFixture] 属性.因此,TestDriven.NET 仍将运行您的各个测试函数,但会作为 Ad Hoc(在测试时通过/失败/跳过消息的末尾显示).

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).

我通过安装完全支持 NUnit 2.6 的较新版本 TestDriven.NET (3.3 Beta 2) 解决了这个问题(请参阅:https://groups.google.com/d/msg/nunit-discuss/pTCDx2_L8jU/TlpULzE36wEJ) 现在您应该能够在夹具中运行所有测试立即查看 (NUnit 2.6.0) 显示在测试输出的末尾.

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.

这篇关于使用 TestDriven.NET 和 NUnit 在测试类中运行所有测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆