使用 NUnit Console Runner 和 SpecFlow 运行多个标签时,我得到不正确的结果
这是我之前关于设置标签的问题的后续:我可以在 SpecFlow 中使用标签来确定要使用的正确环境吗? 并从这些标签设置变量:如何设置 URL在 NUnit/SpecFlow 框架中使用的变量
我设置了一些变量来帮助填充我的 NUnit 测试,但我发现当 NUnit 运行程序找到适合第一个标签的测试时,测试会使用的设置第二个标签。由于标签对我来说很重要,不仅知道要运行什么测试,还知道要使用什么变量,这给我带来了问题。
因此,如果我有以下标签:
@first
@first @second
@Second
如果我运行 @Second 一切都很好。如果我运行@first,我会得到任何只有@first的场景,但是当涉及到我同时拥有@first和@second的场景时,场景就会运行,因为@first在那里,但是,它使用@second的参数。由于我通过 NUnit-Console 运行 DLL,并且测试是通过 SpecFlow 编写的,所以我不确定问题可能出在哪里。
有人对设置测试以这样的方式运行有建议吗?
This is a follow up to my earlier questions on setting up tags: Can I use tags in SpecFlow to determine the right environment to use? and setting up variables from those tags: How to set up a URL variable to be used in NUnit/SpecFlow framework
I've set up some variables to aid in populating my NUnit Tests, but I find that when the NUnit runner finds the test that fits the first tag the test runs it with the settings of the second tag. Since the tags are important to me to not only know what test to run, but what variables to use, this is causing me problems.
So if I have the following tags:
@first
@first @second
@second
If I run @second everything is fine. If I run @first I get any scenario that has only @first fine, but when it comes to scenarios where I have both @first @second the scenario is run, because @first is there, however, it uses the parameters for @second. Since I am running the DLL through the NUnit-Console and the Tests are written through SpecFlow I am not sure where the issue may lie.
Does anyone have advice on setting up tests to run like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不是很具体,但听起来您有一个如下所示的功能文件:
看起来您正在通过运行“第一个”类别中的所有测试来选择要在 NUnit 中运行的测试。
如果您像这样设置事件定义:
如果您执行场景 C,则
FirstSettings()
和SecondSettings()
将在其之前执行。这与您是否使用@second
类别选择要在 NUnit 下运行的测试无关。这几乎肯定是您看到第二个设置应用于带有两个标签的测试的原因 - 我希望第二个设置覆盖第一个设置,对吧?
对于设置这样的测试,我的唯一建议是将事件等绑定到特定标签可能有用,但应尽可能少地使用。相反,使您的各个步骤定义可重用,并在可能的情况下使用
Given
步骤设置您的测试环境。You've not been very specific, but it sounds like you have a feature file like this:
It looks like you are selecting tests to run in NUnit by running all the tests in the "first" category.
If you set up event definitions like this:
If you execute scenario C then
FirstSettings()
andSecondSettings()
will be executed before it. This is regardless of whether you used the@second
category to select the test to run under NUnit.This is almost certainly the reason that you are seeing the second settings applied to your test with both tags - I expect the second settings overwrite the first ones, right?
My only advice for setting up tests like this, is that binding events and so on to specific tags can be useful but should be used as little as possible. Instead make your individual step definitions reusable, and set up your test environment, where possible, with
Given
steps.