具有Result属性的Nunit TestCase属性工作不正确吗? [英] Does Nunit TestCase attribute with Result property work incorrect?

查看:140
本文介绍了具有Result属性的Nunit TestCase属性工作不正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我为Nunit 2.6(使用2.6.0.12035版本)编写了下一个测试"测试:-)

So, I wrote next "test" test :-) for Nunit 2.6 (use 2.6.0.12035 ver.)

    [TestCase(1, 2, Result = 3)]
    [TestCase(3, 4, Result = 7)]
    [TestCase(5, 6, Result = 11)]
    public int Add_Test(int a, int b)
    {
        return a - b;
    }

接下来,我使用Resharper 6.1.37.86运行它. Resharper显示所有三个测试均通过. 比我尝试使用nunit GUI-nunit.exe运行测试.测试失败,并显示奇怪的错误消息:方法具有非空返回值". 实际上,所有测试都将失败,并带有意外的结果值. 这个功能工作不正确还是我做不到?错误的? 顺便说一句,接下来,我尝试不设置Result属性,它对两个跑步者都适用:

Next, I run it with Resharper 6.1.37.86. Resharper shows that all three test are passed. Than I try to run test with nunit GUI - nunit.exe. Tests fall with strange error message: "Method has non-void return value". In fact all tests should fail with unexpected value of result. Does this feature work incorrect or I do smth. wrong? By the way, next I try do without set Result property and it works perfect with both runners:

    [TestCase(1, 2, 3)]
    [TestCase(3, 4, 7)]
    [TestCase(5, 6, 11)]
    public void Add_Test1(int a, int b, int result)
    {
        Assert.AreEqual(result, a - b);
    }

推荐答案

无论我使用NUnit.exe还是NUnit-console.exe,我在NUnit 2.6.0.12035中都遇到相同的问题.

I get the same problem with NUnit 2.6.0.12035, whether I use NUnit.exe or NUnit-console.exe.

您的示例可以使用NUnit.exe 2.5.10正常运行. (我的猜测是Resharper使用的是NUnit 2.5.10,因此测试通过了.)

Your example works fine using NUnit.exe 2.5.10. (My guess is that Resharper is using NUnit 2.5.10 and so the test passes.)

已报告该问题到NUnit论坛.

编辑:我的测试程序集引用了 NUnit.framework.dll 的2.5.10版本.如果我切换为使用2.6.0.12035版本,则该测试将同时对 NUnit.exe NUnit-console.exe 正常运行.我敢打赌,你的问题是一样的.

My test assembly was referencing the 2.5.10 version of NUnit.framework.dll. If I switch to use the 2.6.0.12035 version, the test works as expected with both NUnit.exe and NUnit-console.exe. I'll bet your issue is the same.

它已作为错误提交,并已已修复在下一个版本中.如果您的单元测试库链接到旧版本的 Nunit.framework.dll ,则2.6中的测试运行程序将不再导致错误.

Edit 2: It has been submitted as a bug and fixed in the next release. The test runners in 2.6 will no longer cause an error if your unit test library links to an older version of Nunit.framework.dll.

这篇关于具有Result属性的Nunit TestCase属性工作不正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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