How to Configure Specflow 3.0.199 with NUnit 3.11?

蓝咒 提交于 2020-01-11 13:57:45

问题


I have done this a couple of times before, but it's not working today. Am I missing something?

I want to configure Specflow from the scract, using NUnit and to execute inside Visual Studio. I've seen many tutorials but they are not working to me :P. I'm trying to use the latest versions.

These are the steps I'm doing on Visual Studio 2017:

  • Create a test project (.NET Framework)
  • Install Specflow plugin for Visual Studio (Tools > Extensions and Updates)
  • Delete reference of MSTests from the nuget packages.
  • Install SpecFlow 3.0.199
  • Install NUnit 3.11
  • Install SpecRun.Runner 3.0.284

After creating a default feature file and generate its steps, when I compile the solution I get this error on CalculatorFeature.feature.cs (the generated file):

It's like those configurations are not compatible. What's going on? If you have another step by step list, let me know how to configure Specflow with NUnit to run on Visual Studio 2017, please.


回答1:


For SpecFlow 3 you have to use the MSBuild generation.

To this, follow these two steps:

  1. Add the NuGet package SpecFlow.Tools.MsBuild.Generation with the same version as SpecFlow to your project
  2. Remove all SpecFlowSingleFileGenerator custom tool entries from your feature files.

From https://specflow.org/2019/generating-code-behind-files-using-msbuild/

Background what is happening:

The VS Extension has sometimes problems to find the used SpecFlow version. In that case, it falls back to the SpecFlow version shipped with the extension (which is really old). This version is generating code with now not existing NUnit attributes.




回答2:


TestFixtureSetUp and TestFixtureTearDown attributes were deprecated for quite some time and were finally removed. They are replaced by OneTimeSetUp and OneTimeTearDown.

Your choices are probably...

  1. Go back to an NUnit version that supports the old attributes.

  2. Get a version of SpecFlow that uses the new attributes.

  3. Find a way to configure SpecFlow and tell it to use the new attributes. Sorry, but this option, which is no doubt the best, is out of my wheelhouse.



来源:https://stackoverflow.com/questions/55691940/how-to-configure-specflow-3-0-199-with-nunit-3-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!