I know that this was asked a long time ago, but what I think you want, maybe there are several ways to achieve this, as I understand it. In fact, you really want to define a function once, but disable the steps that call for this function, based on whether you are calling an internal service, a public web service, or WebApp. There is a discussion of various approaches to solving this issue in the mailing list , but the essence of this is as follows (the example shows the API vs UI, but the same applies to your internal vs web service vs webapp, which I consider):
Option 1 #
(thanks to Oliver Friedrich from the mailing list)
you need to create one assembly for each of the parameters that you want to change for the steps, so one for internal, one for web service and one for webapp. You say that to tell about all the different assemblies in the config, for example:
<specFlow> <stepAssemblies> <stepAssembly assembly="Tests.API" /> <stepAssembly assembly="Tests.UI" /> </stepAssemblies> </specFlow>
then in your general test steps you have some kind of step [BeforeTestRun] , which chooses which assembly to load the steps:
[Binding] public class TestRunSetup {
Option 2 ##
(thanks to Gรกspรกr Nagy from the mailing list)
Try generating tests at build time . I donโt know exactly how this will work, but this is an area that we can explore.
Option 3 ##
(thanks to Dan Mork from the mailing list)
If you are using SpecFlow's dependency injection capabilities, you can create an interface to make the calls you want to use and use this in a common set of steps. Then you can have 3 implementations of this interface, one of which calls your back-end service that calls the web service, and one that manages the web application. It remains only to enter the correct implementation of this interface into the files of the steps of the stack, which can be done as follows:
This still leaves you a problem with registering. This will depend on the features of your decision, your build environment, test runtime, etc. Some options for this ...
- for
BeforeScenarioAttribute - create two different build configurations for your project. each defines different constants and uses precompiler directives to build the correct registrations in the code
- add conditional logic to check environment variable
- add conditional logic to verify configuration settings
- I did not check, but perhaps
ScopeAttribute expanding for you should create a subclass and provide your own logic for the BeforeScenarioAttribute method to be BeforeScenarioAttribute .
Hope this gives you some options to do what you want.
IMHO the first option is probably the best, although option 3 is also pretty sweet.