dependency-injectioncucumbercucumber-javacucumber-junitpicocontainer

Multiple ObjectFactory instances for cucumber


I wrote a set of feature files for testing a custom framework and I want to allow testing of specific implementations of the interfaces of the framework. I want to run a whole lot of features with different implementations.

To do that, I have created a custom ObjectFactory and passing implementations using PicoContainer dependency injection. I added this factory to a cucumber.properties file and it works just fine. The only problem is - what if I have more than one set of implementations to test?

I can create several ObjectFactories, but how can I run the tests multiple times with different factories? Is it possible to pass ObjectFactory implementation to Runner class, using annotation or something alike? I run features with JUnit runner, and if I can have several of them with different factories, it should work, I think. However the only option to specify ObjectFactory I've found is cucumber.options file which is one for a module...


Solution

  • Currently it is not possible to use multiple object factories in Cucumber. As a work around you could implement a single object factory that delegates to a different object factory depending on some environment variable.

    You may also want to consider using cucumber-spring instead of cucumber-pico as cucumber-spring can pick up springs context configuration annotations from step definitions. This can be done with minimal configuration if you structure your project like this:

     | - runners 
     | | - CucumberConfigATest.java // @CucumberOptions(glue="steps", extraGlue="config.a") 
     | | - CucumberConfigBTest.java // @CucumberOptions(glue="steps", extraGlue="config.b")
     | - steps
     | | - SomeSteps.java
     | | - MoreSteps.java
     | - config
     | | - a
     | | | - StepsWithContextConfigA.java
     | | - b
     | | | - StepsWithContextConfigB.java