如何在 Visual Studio 2010 中运行 SpecFlow 测试?

发布于 2024-09-04 20:17:10 字数 233 浏览 3 评论 0原文

尝试使用全新的 VS2010 Professional 安装来运行 SpecFlow。创建了一个新的控制台应用程序并添加了对 NUnit 和 SpecFlow 的引用。创建了 SpecFlow 功能。将创建具有默认模板代码的 .feature。

现在我尝试运行这个测试,但我不明白如何运行。当我右键单击该项目(在顶层)时,鼠标下拉菜单中没有“运行测试”选项。 SpecFlow 安装不正确吗?我是否缺少一些参考资料或需要安装的其他工具?

Trying to get SpecFlow running with a fresh VS2010 Professional install. Created a new console application and added references to NUnit and SpecFlow. Created a SpecFlow feature. The .feature with the default template code is created.

Now I try to run this test, but I don't understand how. When I right-click the project (at the top-level), there is no "Run test(s)" option in the mouse drop down menu. Didn't the SpecFlow install correctly, am I missing some references or some other tool I need to install?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(8

知足的幸福 2024-09-11 20:17:10

如果您希望能够直接从 Visual Studio 2010 运行测试,而不需要任何其他工具或扩展,那么您应该将 SpecFlow 配置为使用 MsTest 作为其单元测试框架。

这可以通过以下方式在应用程序配置文件中完成:

  <configSections> 
    <section 
       name="specFlow" 
       type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/> 
  </configSections> 
  <specFlow> 
    <unitTestProvider name="MsTest" /> 
    <!--
        Use this if you're running VS2010
        <unitTestProvider name="MsTest.2010" />
    -->
  </specFlow> 

生成的代码隐藏文件将包含 Visual Studio 可以识别的 MsTest 测试,并且可以使用 build-it 测试运行程序运行。

根本不需要使用 NUnit。

If you want to be able to run your tests directly from Visual Studio 2010 without any additional tools or extensions than you should configure SpecFlow to use MsTest as its unit test framework.

This can be done in your application configuration file with the following:

  <configSections> 
    <section 
       name="specFlow" 
       type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/> 
  </configSections> 
  <specFlow> 
    <unitTestProvider name="MsTest" /> 
    <!--
        Use this if you're running VS2010
        <unitTestProvider name="MsTest.2010" />
    -->
  </specFlow> 

The generated code-behind file will then contain MsTest tests that are recognisable by Visual Studio and can be run with the build-it test runner.

No need to use NUnit at all.

莫言歌 2024-09-11 20:17:10

SpecFlow 本身不提供运行器。

SpecFlow 为常见的单元测试框架之一生成固定装置。在 SpecFlow 1.3 NUnit(默认)中,支持 MSTest 和 xUnit.net(在 App.config 中配置)。

要运行这些装置,您必须使用能够运行它们的运行器。
对于集成在 VisualStudio 中的测试运行器来说,ReSharper 是一个非常好的选择,但它不是免费的。 ReSharper 在您所指的解决方案资源管理器中为您提供“运行单元测试”上下文菜单。

VisualStudio 集成的替代方案是 TestDriven.Net(也提供上下文菜单)。

对于 NUnit,您还可以使用 NUnit 本身附带的运行程序(有一个 GUI 运行程序和一个命令行运行程序)。

对于 MSTest,您可以使用本机 VisualStudio 集成来运行测试(但我发现这有点笨拙)。

xUnit.net 也附带了它的运行程序,但我对它们不熟悉。

此外,您可以使用 MSBuild 任务来运行装置...

SpecFlow does not provide a runner itself.

SpecFlow generates fixtures for one of the common Unit-Test-Frameworks. In SpecFlow 1.3 NUnit (default), MSTest and xUnit.net are supported (configured in the App.config).

To run the fixtures you have to use a runner that is capable of running them.
ReSharper is a very good option for a test runner that is integratied in VisualStudio, but it is not free. ReSharper gives you the "Run Unit Tests" context menu in the solution explorer, you are referring to.

An alternative for VisualStudio integration is TestDriven.Net (also providing a context menu).

For NUnit you can also use the runners that come with NUnit itself (there is a GUI-Runner and a commandline runner).

For MSTest you can use the native VisualStudio integration for running tests (however I find that one a bit clumsy).

xUnit.net also comes with its runners, however I am not familiar with them.

Furthermore, you can use MSBuild tasks to run the fixtures ...

何以心动 2024-09-11 20:17:10

只是为了更新这个问题,在您应该使用的最新版本的specflow中,(使用MsTest.2010)

<configSections> 
    <section 
       name="specFlow" 
       type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/> 
  </configSections> 
  <specFlow> 
    <unitTestProvider name="MsTest.2010" /> 
  </specFlow> 

请参阅SpecFlow错误地使用 NUnit

Just to update this questions, in the latest versions of specflow you should use, (use MsTest.2010)

<configSections> 
    <section 
       name="specFlow" 
       type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/> 
  </configSections> 
  <specFlow> 
    <unitTestProvider name="MsTest.2010" /> 
  </specFlow> 

see SpecFlow wrongly using NUnit

不必你懂 2024-09-11 20:17:10

我写了一篇博客文章,介绍如何使用批处理文件作为外部工具来自动运行 NUnit 中的 SpecFlow 功能并生成 html 报告。请参阅:http://watirmelon.com/2011/ 02/18/c-sharp-atdd-on-shoestring/

I have written a blog post on how to use a batch file as an external tool to automatically run SpecFlow features in NUnit and generate a html report. See: http://watirmelon.com/2011/02/18/c-sharp-atdd-on-a-shoestring/

青瓷清茶倾城歌 2024-09-11 20:17:10

有件事让我着迷。我必须确保项目类型是测试项目。我必须卸载该项目并将项目 GUID 更改为单元测试项目的 GUID。一旦我这样做了,项目中的 SpecFlow(以及任何其他)测试就开始了

Something that caught me out. I had to ensure that the Project Type was a Test Project. I had to unload the project and change the Project GUID to that of a Unit Test Project. Once I did that the SpecFlow (and any other) test in the project sprang to life

失眠症患者 2024-09-11 20:17:10

Specflow 测试使用 NUnit (GUI) 运行,需要从外部调用,或者可以安装 TestDriven.net 或 Resharper 以支持从 Visual Studio 内部运行测试。

The Specflow tests are run using the NUnit (GUI), which needs to be invoked externally or alternatively TestDriven.net or Resharper can be installed to support running the tests from inside Visual Studio.

演多会厌 2024-09-11 20:17:10

我创建了一个视频,演示如何在 VS2010 中使用 Specflow 此处

I have created a video demonstrating how to use Specflow with VS2010 here

厌味 2024-09-11 20:17:10

您还可以尝试 Visual Nunit,它是 Visual Studio 2008 和 2010 的开源 NUnit 测试运行器插件。使用 NuGet 获取它,有关详细信息,请参阅 http://www.bubblecloud.org/visualnunit

You can also try Visual Nunit, an open source NUnit test runner plugin to Visual Studio 2008 and 2010. Get it using NuGet, for more info see http://www.bubblecloud.org/visualnunit

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