Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specflow step definition classes in different projects

Tags:

specflow

Is it possible to have two step definition classes with first being in one namespace/project, and second in another one? I have like this:

My test project which I run: namespace: ABZ.ExcelTest class name: ABZ.ExcelTest.ExcelStepDefinition

My other project which is Logic for testing: namespace: ABZ.OfficeAddInTestLogic class name: ABZ.OfficeAddInTestLogic.StepDefinition

I have [Binding] attribute on both my classes but this one which is not in test project (ABZ.OfficeAddInTestLogic.StepDefinition) cannot be found, I get NUnit error:

No matching step definition found for the step. Use the following code to create one: ...

Is it possible to have 2 step definition classes in different projects?

like image 926
Vajda Avatar asked Mar 18 '11 17:03

Vajda


People also ask

How do you link a feature file with step definitions in SpecFlow?

Right-click on any step of the Feature File, then click on Generate Step Definitions option. In the Generate Step Definition Skeleton pop-up, check the steps for which we want to generate the implementation. Add a Class Name, then click on the Generate button.

How do you generate step definitions in SpecFlow?

Open your feature file. Right-click in the editor and select Define steps… from the menu. Enter a name for your class in the Class name field. Click on create to generate a new step definition file or use the Copy methods to clipboard method to paste the skeleton code in an existing step definition file.

Which attribute in SpecFlow binds the class to step file?

You have to add the [Binding] attribute to the class where your step definitions are: [Binding] public class StepDefinitions { ... } > Note: Bindings (step definitions, hooks) are global for the entire SpecFlow project.


2 Answers

Yes it is - that feature is called External steps (see https://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/ExternalSteps/ExternalSteps.feature)

What you probably are missing is an app.config setting like this:

<specFlow>  
<stepAssemblies>
  <stepAssembly assembly="ExternalStepsCS" />
</stepAssemblies>

That will look for steps in an external assembly called ExternalStepsCS in this case.

like image 66
Marcus Hammarberg Avatar answered Oct 15 '22 11:10

Marcus Hammarberg


I will often have a "Test Helpers" library, with common code shared between multiple test projects. I'll have a class in this shared library, let's call it CucumberBase. Then, in my actual test project, I'll have a class like this:

[Binding]
public class SomeFeatureSpecs : CucumberBase
{
    ...
}

Every public CucumberBase method that is tagged with [Given()]/[When()]/[Then()]/etc. gets picked up correctly in my actual test project, within the SomeFeatureSpecs class. This lets me override and extend common functionality as well.

like image 1
Thought Avatar answered Oct 15 '22 13:10

Thought