针对不同配置的多个 [SetupTest]
一个装置中是否可以有多个 [SetupTest]?
我正在使用 Selenium 和 nUnit,并且希望能够指定用户想要测试的浏览器。
我有一个简单的用户 GUI 用于选择要运行的测试,但是我知道将来我们希望将其连接到巡航控制以自动运行测试。理想情况下,我希望测试可以在我们的 GUI 和 NUnit GUI 上运行。
Is it possible to have multiple [SetupTest]'s in a fixture?
I am using Selenium and nUnit and would like to be able to specify the Browser on which the user wants to test.
I have a simple user GUI for selecting tests to run but, I am aware that in the future we want to hook this up to cruise control to run the tests automatically. Ideally I want tests that can be run on both our GUI and the NUnit GUI.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个装置中是否可以有多个 [SetupTest]?不。
可以在基类中定义所有测试,让多个固定装置继承测试,然后在运行时选择依赖于环境的固定装置类型。
这是我为 [TestFixtureSetup] 准备的库存示例。同样的原则适用于所有设置属性。请注意,我只将 [TestFixture] 放在子类上。由于基础“TestClass”没有完整的设置代码,因此您不想直接运行测试。
Is it possible to have multiple [SetupTest]'s in a fixture? No.
It is possible to define all your tests in a base class, have multiple fixtures inherit the tests, and then select an environment dependent fixture type at runtime.
Here’s the stock example that I have for [TestFixtureSetup]. The same principle works for all the setup attributes. Notice that I’m only putting [TestFixture] on the child classes. Since the base “TestClass” doesn’t have complete setup code, you don’t want to run the tests directly.
我怀疑您可以使用 NUnit 2.5 中引入的参数化测试来完成您想要的操作,但我并不完全清楚您想在这里做什么。但是,您可以定义固定装置并让它在其构造函数中采用浏览器变量,然后使用参数化的 TestFixture 属性,例如
参见 NUnit 文档 了解更多信息。
Setup 属性标识每次测试之前运行的方法。每个测试夹具只有一个设置才有意义 - 将其视为每次测试运行之前的“重置”或“准备”。
I suspect you can use the parameterized tests introduced in NUnit 2.5 to do what you want, but I'm not totally clear what you want to do here. However, you could define the fixture and have it take a Browser variable in its constructor, then use parameterized TestFixture attributes like
See NUnit Documentation for more info.
The Setup attribute identifies a method that is run before each test. It only makes sense to have one Setup per test fixture - think of it as a 'reset' or 'preparation' before each test is run.