当它包含数组NUnit的不能识别一个TestCase [英] NUnit cannot recognise a TestCase when it contains an array

查看:116
本文介绍了当它包含数组NUnit的不能识别一个TestCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是很简单,但令人讨厌的行为,我正在与NUnit的:

This is quite simple but annoying behaviour I am running into with NUnit:

我有一些像这样的测试:

I have some tests like this:

[Test]
[TestCase( 1, 2, "hello" )]
[TestCase( 3, 5, "goodbye" )]
public void MyClass_MyMethod( int a, int b, string c )
{
    Assert.IsTrue( a < b );
}

这工作正常,并在ReSharper的NUnit的窗格中我可以看到每个测试用例获取其。在结果自己的响应

This works fine and in the ReSharper NUnit pane I can see each TestCase getting its own response in the result.

我有一个看起来像这样的第二个测试用例:

I have a second TestCase that looks like this:

[Test]
[TestCase( 1, 2, new long[] { 100, 200 })]
[TestCase( 5, 3, new long[] { 300, 500 })]
public void MyClass_MyOtherMethod( long a, long b, long[] bunchOfNumbers )
{
   Assert.IsTrue( a < b );
}

当我运行它,我看到这一点:

When I run it I see this:

一个或多个子测试有错误的异常不具有堆栈跟踪

One or more child tests had errors Exception doesn't have a stacktrace

公共无效MyClass_MyOtherMethod(5,3 ,System.Int64 [])失败。

public void MyClass_MyOtherMethod(5,3,System.Int64[]) failed

区别在于与我的其他测试中,它引出的每个测试用例作为在一个单独的复选框测试列表,而这一次没有得到显示和我有没有细节,直到我在调试器中运行,以什么地方出了错和地点。我有点担心这个测试将如何表现在构建机上。没有人有任何想法是怎么回事,为什么

The difference being that with my other tests it draws out each TestCase as a separate checkbox on the test list, whereas this one does not get shown and I have no detail until I run it in a debugger as to what went wrong and where. I am a little concerned about how this test will behave on the build machine. Does anyone have any idea what is going on and why?

推荐答案

从的在JetBrains的这个bug 的它看起来好像这里的解决方案是使用测试名属性上的不同情况

Following on from this bug at JetBrains it looks as though the solution here is to use the TestName attribute on your different cases:

[Test]
[TestCase( 1, 2, new long[] { 100, 200 }, TestName="Test 1" )]
[TestCase( 5, 3, new long[] { 300, 500 }, TestName="Test 2" )]
public void MyClass_MyOtherMethod( long a, long b, long[] bunchOfNumbers )
{
   Assert.IsTrue( a < b );
}



一切现在显示正确ReSharper的,如果我的测试之一发生故障。

Everything now shows correctly in ReSharper if one of my tests fails.

这篇关于当它包含数组NUnit的不能识别一个TestCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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