SpecFlow 错误地使用 NUnit [英] SpecFlow wrongly using NUnit

查看:52
本文介绍了SpecFlow 错误地使用 NUnit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我(今天)第一次尝试了 SpecFlow.我正在通过在 VS2010 Pro 中创建一个新的类库并添加一个 SpecFlow Feature Definition 文件来进行尝试.

I've just (today) tried SpecFlow for the first time. I'm playing about by creating a new class library in VS2010 Pro and adding a SpecFlow Feature Definition file.

问题是,集成似乎工作不正常,出现了各种不同的错误.我选择 MsTest 作为测试运行程序,因为我不会为调用 NUnit 而烦恼(我想长期使用 NUnit,但目前我只想让一些 BDD 代码工作).然而,生成的代码文件继续引用 NUnit - 这显然是错误的,因为我刚刚告诉 SpecFlow 使用 MsTest 运行.我已经做了所有我能想到的再次调用代码生成的工作,包括创建一个全新的类库项目,并在工具 > 选项 > SpecFlow 中选择 MsTest 选项.

Thing is, the integration doesn't appear to be working properly, with a variety of different errors. I've selected MsTest as the test runner, because I can't be bothered with invoking NUnit (I'd like to use NUnit in the long term but at the moment I just want to get some BDD code working). The generated code files however continue to reference NUnit - which is obviously wrong, since I've just told SpecFlow to run using MsTest. I've done everything I can think of to invoke the code generation again, including creating a brand new class library project with the MsTest option selected in Tools > Options > SpecFlow.

如果我将测试运行程序字段设置为自动"并右键单击功能文件,然后选择运行 SpecFlow 方案",我会收到一条错误消息找不到匹配的测试运行程序".

If I leave the test runner field set to 'Auto' and right-click a feature file, then select 'Run SpecFlow Scenarios' I get an error message "Could not find matching test runner".

如果我改为将测试运行器字段更改为 MsTest,我会在执行相同操作时收到不同的错误消息 - 未将对象引用设置为对象的实例".我对此并不感到惊讶,因为它仍在尝试运行 NUnit 测试,即使我已经明确要求使用 MsTest,但显然它不应该 nullref 并将其呈现给用户.

If I instead change the test runner field to MsTest, I get a different error message on doing the same thing - "Object Reference not set to an instance of an object". I'm not surprised at this one since it's still trying to run NUnit tests even though I've explicitly asked for MsTest, though obviously it shouldn't nullref and present that to the user.

我做错了什么?该文档没有帮助,据我所知,没有常见问题解答.

What am I doing wrong? The documentation is not helpful, and as far as I can see, there's no FAQ.

编辑 #1:我已经确定我正在寻找的实际设置是使用 App.Config 提供的,使用字段 <unitTestProvider name="MsTest"/>.我可以看到发生了什么 - Visual Studio 选项菜单中的字段似乎没有修改您当前正在处理的项目.问题是,这使得该领域看起来根本没有做任何事情.我现在已经说服 SpecFlow 生成 MsTest 类并使用 MSTest 运行程序运行.

edit #1: I've established that the actual setting I'm looking for is provided using App.Config using the field <unitTestProvider name="MsTest" />. I can see what's happened - the field in the Visual Studio options menu doesn't seem to modify the project you're currently working on. Thing is, this makes it look like that field doesn't do anything at all. I've now persuaded SpecFlow to generate MsTest classes and run using the MSTest runner.

所以现在问题变成了一个稍微不同的问题:工具 > 选项 > SpecFlow > 测试运行器工具字段做什么(如果有的话)?

So now the question morphs into a slightly different one: What (if anything) does the Tools > Options > SpecFlow > Test Runner Tool field do?

推荐答案

对于 VS2010,正确的值是 MsTest.2010,而不是文档中的 MsTest.更改您的 app.config(用于测试程序集),它会正常工作(至少在 SpecFlow 1.8 中)

With VS2010 the correct value is MsTest.2010 not MsTest as documented. Change your app.config (for the test assembly) and it will work fine (at least with SpecFlow 1.8)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>
  <specFlow>
      <unitTestProvider name="MsTest.2010" />
      <!-- For additional details on SpecFlow configuration options see https://github.com/techtalk/SpecFlow/wiki/Configuration -->
  </specFlow>
</configuration>

这篇关于SpecFlow 错误地使用 NUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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