使用 NUnit Console Runner 和 SpecFlow 运行多个标签时,我得到不正确的结果

发布于 2024-12-15 04:54:10 字数 783 浏览 2 评论 0原文

这是我之前关于设置标签的问题的后续:我可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2024-12-22 04:54:10

您不是很具体,但听起来您有一个如下所示的功能文件:

@first
Scenario: A - Something Specific happens under the first settings
    Given ...etc...

@second
Scenario: B - Something Specific happens under the second settings
    Given ...etc...

@first @second
Scenario: C - Something general happens under the first and second settings
    Given ...etc...

看起来您正在通过运行“第一个”类别中的所有测试来选择要在 NUnit 中运行的测试。

如果您像这样设置事件定义:

[BeforeFeature("first")] 
public static string FirstSettings() 
{ ... }

[BeforeFeature("second")] 
public static string SecondSettings() 
{ ... }

如果您执行场景 C,则 FirstSettings()SecondSettings() 将在其之前执行。这与您是否使用 @second 类别选择要在 NUnit 下运行的测试无关。

这几乎肯定是您看到第二个设置应用于带有两个标签的测试的原因 - 我希望第二个设置覆盖第一个设置,对吧?

对于设置这样的测试,我的唯一建议是将事件等绑定到特定标签可能有用,但应尽可能少地使用。相反,使您的各个步骤定义可重用,并在可能的情况下使用 Given 步骤设置您的测试环境。

You've not been very specific, but it sounds like you have a feature file like this:

@first
Scenario: A - Something Specific happens under the first settings
    Given ...etc...

@second
Scenario: B - Something Specific happens under the second settings
    Given ...etc...

@first @second
Scenario: C - Something general happens under the first and second settings
    Given ...etc...

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:

[BeforeFeature("first")] 
public static string FirstSettings() 
{ ... }

[BeforeFeature("second")] 
public static string SecondSettings() 
{ ... }

If you execute scenario C then FirstSettings() and SecondSettings() 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文