NUnit的。传递参数到拆卸的方法 [英] NUnit. Passing parameters into teardown method

查看:224
本文介绍了NUnit的。传递参数到拆卸的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NUnit的。我已经定义likeso我的测试方法:

I'm using NUnit. I have my test method defined likeso:

[Test]
[TestCase("Fred", "Bloggs")]
[TestCase("Joe", "Smith")]
public void MyUnitTest(string firstName, string lastName)
{
    ...
}

在一个TestCase已经完成,它进入拆机方法。什么了喜欢做的事,就是有被传递到测试方法,但也被传递到拆机方法的TestCase的参数。

After a TestCase has finished, it goes into the TearDown Method. What'd like to do, is have those TestCase parameters that are passed into the test method but also passed into the TearDown method.

事情是这样的:

[TearDown]
public void TearDown(string firstName, string lastName)
{
  ...
}

我希望NUnit的支持此外的开箱。否则,我需要在测试方法来存储集合中的测试数据编写定制的代码。然后,该集合在拆机方法使用。

I'm hoping that NUnit supports this out-of-the-box. Otherwise, I need to write bespoke code in the test method to store the test data in a collection. Then that collection is used in the TearDown method.

如果任何人有任何想法..将是巨大的!
感谢。
基督教

If anyone has any thoughts .. would be great! Thanks. Christian

推荐答案

TearDown中和安装在测试夹具为你的每个测试的执行。考虑你有以下测试:

TearDown and SetUp are executed for each of your tests in test fixture. Consider you have following tests:

[TestCase("Joe", "Smith")]
public void Test1(string firstName, string lastName) { ... }

[Test]
public void Test2() { ... }

[TestCase(10)]
public void Test3(int value) { ... }

什么是预期的签名TearDown中的方法?

What is expected signature of TearDown method?

所以,答案是否定的。 NUnit的不提供通过测试参数TearDown中方法的默认方式。而且我认为不会。您需要手动添加此功能。

So, answer is no. NUnit does not provide default way of passing test parameter to TearDown method. And I think it won't. You need to add this functionality manually.

这篇关于NUnit的。传递参数到拆卸的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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