开发者

Specflow step definition classes in different projects

开发者 https://www.devze.com 2023-02-17 22:21 出处:网络
Is it possible to have two step definition classes with first being in one namespace/project, and second in another one?

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.StepDefinitio开发者_C百科n

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消