Multiple ObjectFactory instances for cucumber2019 Community Moderator ElectionGoogle Guice vs. PicoContainer for Dependency InjectionInjecting Mockito mocks into a Spring beanInversion of Control vs Dependency InjectionHow do I set the path to my Cucumber features using cucumber-junit?What setups are necessary to run Cucumber with tags in Eclipse?Running Cucumber tests directly from executable jarWhy are my cucumber tests cases getting skipped?Cucumber framework scenarios not found when picocontainer jar is added to java build pathDifference in running Cucumber-JVM vs Cucumber runner(Junit)Cucumber-Why does automation browser not launch on running the testrunner class

Why is my explanation wrong?

Is there a math expression equivalent to the conditional ternary operator?

What is the best index strategy or query SELECT when performing a search/lookup BETWEEN IP address (IPv4 and IPv6) ranges?

Short story about an infectious indestructible metal bar?

What can I do if someone tampers with my SSH public key?

Unidentified signals on FT8 frequencies

Paper published similar to PhD thesis

Should I apply for my boss's promotion?

How does learning spells work when leveling a multiclass character?

A running toilet that stops itself

Draw this image in the TIKZ package

How can I have x-axis ticks that show ticks scaled in powers of ten?

What is the purpose of a disclaimer like "this is not legal advice"?

I am the person who abides by rules but breaks the rules . Who am I

Can multiple states demand income tax from an LLC?

Was this cameo in Captain Marvel computer generated?

What is the orbit and expected lifetime of Crew Dragon trunk?

Why restrict private health insurance?

Create chunks from an array

Rationale to prefer local variables over instance variables?

Should we avoid writing fiction about historical events without extensive research?

Professor forcing me to attend a conference, I can't afford even with 50% funding

Generating a list with duplicate entries

How to install "rounded" brake pads



Multiple ObjectFactory instances for cucumber



2019 Community Moderator ElectionGoogle Guice vs. PicoContainer for Dependency InjectionInjecting Mockito mocks into a Spring beanInversion of Control vs Dependency InjectionHow do I set the path to my Cucumber features using cucumber-junit?What setups are necessary to run Cucumber with tags in Eclipse?Running Cucumber tests directly from executable jarWhy are my cucumber tests cases getting skipped?Cucumber framework scenarios not found when picocontainer jar is added to java build pathDifference in running Cucumber-JVM vs Cucumber runner(Junit)Cucumber-Why does automation browser not launch on running the testrunner class










1















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...










share|improve this question


























    1















    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...










    share|improve this question
























      1












      1








      1


      1






      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...










      share|improve this question














      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...







      dependency-injection cucumber cucumber-java cucumber-junit picocontainer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Tatiana DidikTatiana Didik

      1828




      1828






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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





          share|improve this answer




















          • 1





            I came to the same idea with env variable and a factory. Unfortunately, I don't have time to experiment with cucumber-spring, otherwise I'd rather go with this way - it looks a lot cleaner.

            – Tatiana Didik
            2 days ago



















          1














          @mpkorstanje provided an answer I came up with as well. In case someone needs an example of implementation - here it is:



          @RunWith(Cucumber.class)
          @CucumberOptions(features="src/test/resources")
          public class MyRunner

          @BeforeClass
          public static void setup()
          System.setProperty(EventProcessorPicoFactory.EVENT_BUS_HANDLER, IUserECNDataHandler.class.getName());




          public class MyFactory
          public MyObject build()
          String type = System.getProperty("my.property.name");
          switch (type)
          case "my.value":
          return new MyObject();
          default:
          throw new IllegalArgumentException("not implemented");









          share|improve this answer




















          • 1





            Cucumber also supports JUnits before and after class annotations. You don't need to exetend Cucumber. If you are on a recent version of it anyway (I think > 2.0.0).

            – mpkorstanje
            2 days ago











          • I meant rather @BeforeClass, but thanks, I wasn't realizing I can use it in there. Tried to put it into initialization block, but it seemed to be never called - I guess, I need to learn more on how JUnit instantiates test classes

            – Tatiana Didik
            yesterday











          • The initialization is runner dependent. The Cucumber runner doesn't instantiate the test class.

            – mpkorstanje
            yesterday











          • Looks like I was mistaken though. Cucumber currently invokes @BeforeClass rather well after booting up the object factory. This is a bug in the implementation.

            – mpkorstanje
            23 hours ago











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026371%2fmultiple-objectfactory-instances-for-cucumber%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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





          share|improve this answer




















          • 1





            I came to the same idea with env variable and a factory. Unfortunately, I don't have time to experiment with cucumber-spring, otherwise I'd rather go with this way - it looks a lot cleaner.

            – Tatiana Didik
            2 days ago
















          1














          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





          share|improve this answer




















          • 1





            I came to the same idea with env variable and a factory. Unfortunately, I don't have time to experiment with cucumber-spring, otherwise I'd rather go with this way - it looks a lot cleaner.

            – Tatiana Didik
            2 days ago














          1












          1








          1







          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





          share|improve this answer















          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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          mpkorstanjempkorstanje

          2,21022033




          2,21022033







          • 1





            I came to the same idea with env variable and a factory. Unfortunately, I don't have time to experiment with cucumber-spring, otherwise I'd rather go with this way - it looks a lot cleaner.

            – Tatiana Didik
            2 days ago













          • 1





            I came to the same idea with env variable and a factory. Unfortunately, I don't have time to experiment with cucumber-spring, otherwise I'd rather go with this way - it looks a lot cleaner.

            – Tatiana Didik
            2 days ago








          1




          1





          I came to the same idea with env variable and a factory. Unfortunately, I don't have time to experiment with cucumber-spring, otherwise I'd rather go with this way - it looks a lot cleaner.

          – Tatiana Didik
          2 days ago






          I came to the same idea with env variable and a factory. Unfortunately, I don't have time to experiment with cucumber-spring, otherwise I'd rather go with this way - it looks a lot cleaner.

          – Tatiana Didik
          2 days ago














          1














          @mpkorstanje provided an answer I came up with as well. In case someone needs an example of implementation - here it is:



          @RunWith(Cucumber.class)
          @CucumberOptions(features="src/test/resources")
          public class MyRunner

          @BeforeClass
          public static void setup()
          System.setProperty(EventProcessorPicoFactory.EVENT_BUS_HANDLER, IUserECNDataHandler.class.getName());




          public class MyFactory
          public MyObject build()
          String type = System.getProperty("my.property.name");
          switch (type)
          case "my.value":
          return new MyObject();
          default:
          throw new IllegalArgumentException("not implemented");









          share|improve this answer




















          • 1





            Cucumber also supports JUnits before and after class annotations. You don't need to exetend Cucumber. If you are on a recent version of it anyway (I think > 2.0.0).

            – mpkorstanje
            2 days ago











          • I meant rather @BeforeClass, but thanks, I wasn't realizing I can use it in there. Tried to put it into initialization block, but it seemed to be never called - I guess, I need to learn more on how JUnit instantiates test classes

            – Tatiana Didik
            yesterday











          • The initialization is runner dependent. The Cucumber runner doesn't instantiate the test class.

            – mpkorstanje
            yesterday











          • Looks like I was mistaken though. Cucumber currently invokes @BeforeClass rather well after booting up the object factory. This is a bug in the implementation.

            – mpkorstanje
            23 hours ago
















          1














          @mpkorstanje provided an answer I came up with as well. In case someone needs an example of implementation - here it is:



          @RunWith(Cucumber.class)
          @CucumberOptions(features="src/test/resources")
          public class MyRunner

          @BeforeClass
          public static void setup()
          System.setProperty(EventProcessorPicoFactory.EVENT_BUS_HANDLER, IUserECNDataHandler.class.getName());




          public class MyFactory
          public MyObject build()
          String type = System.getProperty("my.property.name");
          switch (type)
          case "my.value":
          return new MyObject();
          default:
          throw new IllegalArgumentException("not implemented");









          share|improve this answer




















          • 1





            Cucumber also supports JUnits before and after class annotations. You don't need to exetend Cucumber. If you are on a recent version of it anyway (I think > 2.0.0).

            – mpkorstanje
            2 days ago











          • I meant rather @BeforeClass, but thanks, I wasn't realizing I can use it in there. Tried to put it into initialization block, but it seemed to be never called - I guess, I need to learn more on how JUnit instantiates test classes

            – Tatiana Didik
            yesterday











          • The initialization is runner dependent. The Cucumber runner doesn't instantiate the test class.

            – mpkorstanje
            yesterday











          • Looks like I was mistaken though. Cucumber currently invokes @BeforeClass rather well after booting up the object factory. This is a bug in the implementation.

            – mpkorstanje
            23 hours ago














          1












          1








          1







          @mpkorstanje provided an answer I came up with as well. In case someone needs an example of implementation - here it is:



          @RunWith(Cucumber.class)
          @CucumberOptions(features="src/test/resources")
          public class MyRunner

          @BeforeClass
          public static void setup()
          System.setProperty(EventProcessorPicoFactory.EVENT_BUS_HANDLER, IUserECNDataHandler.class.getName());




          public class MyFactory
          public MyObject build()
          String type = System.getProperty("my.property.name");
          switch (type)
          case "my.value":
          return new MyObject();
          default:
          throw new IllegalArgumentException("not implemented");









          share|improve this answer















          @mpkorstanje provided an answer I came up with as well. In case someone needs an example of implementation - here it is:



          @RunWith(Cucumber.class)
          @CucumberOptions(features="src/test/resources")
          public class MyRunner

          @BeforeClass
          public static void setup()
          System.setProperty(EventProcessorPicoFactory.EVENT_BUS_HANDLER, IUserECNDataHandler.class.getName());




          public class MyFactory
          public MyObject build()
          String type = System.getProperty("my.property.name");
          switch (type)
          case "my.value":
          return new MyObject();
          default:
          throw new IllegalArgumentException("not implemented");










          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered 2 days ago









          Tatiana DidikTatiana Didik

          1828




          1828







          • 1





            Cucumber also supports JUnits before and after class annotations. You don't need to exetend Cucumber. If you are on a recent version of it anyway (I think > 2.0.0).

            – mpkorstanje
            2 days ago











          • I meant rather @BeforeClass, but thanks, I wasn't realizing I can use it in there. Tried to put it into initialization block, but it seemed to be never called - I guess, I need to learn more on how JUnit instantiates test classes

            – Tatiana Didik
            yesterday











          • The initialization is runner dependent. The Cucumber runner doesn't instantiate the test class.

            – mpkorstanje
            yesterday











          • Looks like I was mistaken though. Cucumber currently invokes @BeforeClass rather well after booting up the object factory. This is a bug in the implementation.

            – mpkorstanje
            23 hours ago













          • 1





            Cucumber also supports JUnits before and after class annotations. You don't need to exetend Cucumber. If you are on a recent version of it anyway (I think > 2.0.0).

            – mpkorstanje
            2 days ago











          • I meant rather @BeforeClass, but thanks, I wasn't realizing I can use it in there. Tried to put it into initialization block, but it seemed to be never called - I guess, I need to learn more on how JUnit instantiates test classes

            – Tatiana Didik
            yesterday











          • The initialization is runner dependent. The Cucumber runner doesn't instantiate the test class.

            – mpkorstanje
            yesterday











          • Looks like I was mistaken though. Cucumber currently invokes @BeforeClass rather well after booting up the object factory. This is a bug in the implementation.

            – mpkorstanje
            23 hours ago








          1




          1





          Cucumber also supports JUnits before and after class annotations. You don't need to exetend Cucumber. If you are on a recent version of it anyway (I think > 2.0.0).

          – mpkorstanje
          2 days ago





          Cucumber also supports JUnits before and after class annotations. You don't need to exetend Cucumber. If you are on a recent version of it anyway (I think > 2.0.0).

          – mpkorstanje
          2 days ago













          I meant rather @BeforeClass, but thanks, I wasn't realizing I can use it in there. Tried to put it into initialization block, but it seemed to be never called - I guess, I need to learn more on how JUnit instantiates test classes

          – Tatiana Didik
          yesterday





          I meant rather @BeforeClass, but thanks, I wasn't realizing I can use it in there. Tried to put it into initialization block, but it seemed to be never called - I guess, I need to learn more on how JUnit instantiates test classes

          – Tatiana Didik
          yesterday













          The initialization is runner dependent. The Cucumber runner doesn't instantiate the test class.

          – mpkorstanje
          yesterday





          The initialization is runner dependent. The Cucumber runner doesn't instantiate the test class.

          – mpkorstanje
          yesterday













          Looks like I was mistaken though. Cucumber currently invokes @BeforeClass rather well after booting up the object factory. This is a bug in the implementation.

          – mpkorstanje
          23 hours ago






          Looks like I was mistaken though. Cucumber currently invokes @BeforeClass rather well after booting up the object factory. This is a bug in the implementation.

          – mpkorstanje
          23 hours ago


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026371%2fmultiple-objectfactory-instances-for-cucumber%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229