[英]NUnit TestFixtures do not work with RestSharp
I'm trying to use NUnit
TestAttributes
to create and delete a RestSharp
RestClient
我正在尝试使用
NUnit
TestAttributes
来创建和删除RestSharp
RestClient
https://github.com/nunit/docs/wiki/TestFixture-Attribute https://github.com/nunit/docs/wiki/TestFixture-Attribute
using NUnit.Framework;
using RestSharp;
namespace Sanitized.Sanitized.Steps
{
[TestFixture]
public class SetupAndTeardown
{
public RestClient restClient;
[SetUp]
public void Init()
{
restClient = new RestClient();
}
[TearDown]
public void Cleanup()
{
restClient = null;
}
}
}
But, I get the error Object reference not set to an instance of an object.
但是,我得到错误
Object reference not set to an instance of an object.
when trying to use this in another class ie with my automated steps. 当试图在另一个类中使用它时,即使用我的自动步骤。
I don't understand this, as I thought code that's in the [SetUp] [Teardown]
attributes are called at the beginning and end of the test respectively. 我不明白这一点,因为我认为
[SetUp] [Teardown]
属性中的代码分别在测试的开始和结束时被调用。
You created a TestFixture
, which is a class that contains tests. 您创建了一个
TestFixture
,它是一个包含测试的类。 If the fixture had any tests, then NUnit would run them and would also run the setup before each test and the teardown after each test. 如果夹具有任何测试,那么NUnit将运行它们,并且还将在每次测试之前运行设置并在每次测试之后进行拆卸。 Since you have no tests, that isn't happening.
由于您没有测试,因此没有发生。 NUnit recognizes the fixture but finds nothing to run there.
NUnit识别夹具,但没有发现任何东西在那里运行。
You say that you have a problem when you "use" this fixture in another class. 当你在另一个类中“使用”这个装置时,你说你有问题。 Test fixtures are not intended to be "used" by other code.
测试夹具不打算被其他代码“使用”。 Rather, they are run by NUnit.
相反,它们由NUnit运行。
For a better answer about how to do what you are trying to do, we first need to know what you are trying to do. 为了更好地回答如何做你想做的事情,我们首先需要知道你想要做什么。 When do you want the "setup" and "teardown" to run?
你什么时候想要“设置”和“拆解”运行? How often should they run?
他们应该多久运行一次? Depending on those things, I can update this answer.
根据这些事情,我可以更新这个答案。
Replying further to your comment... If your tests are in another class, then that class is your test fixture. 回复你的评论......如果你的测试是在另一个类中,那么那个类就是你的测试夹具。 Is there a reason you don't want it to be the fixture?
有没有理由你不希望它成为夹具?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.