简体   繁体   中英

How to share the same step definition across projects within same solution in SpecFlow

  • SpecFlow Version: [ x ] 2.2.1
  • Used Test Runner [ x ]MSTest
  • Visual Studio Version [ x ]VS 2017
  • Are the latest Visual Studio updates installed? [ x ]Yes
  • .NET Framework: [ x ] .NetCore 2.0
  • Test Execution Method: [ x ]Visual Studio Test Explorer

    Section in app.config

Repro Project

I have a solution with multiple test projects under that as below

  • InfoModelApiTests
  • WarmDataTests

Issue Description

I want to use the same step as used in the "InfoModelApiTests" project feature file inside the "WarmDataTests" project's feature file. I don't want to repeat the step definition code. I have included the project reference of "InfoModelApiTests" in the "WarmDataTests" project. And added stepAssemblies reference in the app.config. But I am unable to get the step definition turning into black implying it's been binded.

The step definition class will look as below public sealed class InfoModelApiTestsSteps

Steps to Reproduce

  • Add the project reference of "InfoModelApiTests" in the "WarmDataTests" project
  • Then in the app.config in "WarmDataTests" project add the StepAssemblies as mentioned above
  • Copy the same step from the "InfoModelApiTests" feature file to "WarmDataTests" feature file. It should get binded to the existing step definition.

Answer from https://github.com/techtalk/SpecFlow/issues/1194#issuecomment-402934038


You did it right.
The VS Extension has some problems with additional step assemblies and so the highlighting doesn't work correctly.
But when you execute the tests, it is working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM