question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cucumber-guice Injector specified with the runners properties

See original GitHub issue

Summary

I would like to be able to specify the Injector I want to use inside the CucumberOptions annotation on my runner file. This way I don’t have to create a separate property file for the module.

This is a problem for me since i want to several separate Injectors in the same module

Current Behavior and Expected Behavior

For custom injectors we are required to create a properties file at the root of the classpath. and specify one property in it . guice.injector-source=

Possible Solution

@CucumberOptions(guice.injector-source = "...", ...)
public class Runner {

}

Context & Motivation

  • I am using cucumber to perform my integration test.
  • I want to test the same feature in multiple different enviorments which require different configs.
  • I was planning on using different runners to set up and instantiate the different environments like This is what i am doing now
import org.junit.BeforeClass;
//So i can test against other service that are deployed
public class DeployedTest {
  @beforeClass
  public static before() {
    //start server
    Config config = new config(...);
    Steps.setup(config) //sets up a static the static variables in my step files
  }

}

and

import org.junit.BeforeClass;
//so i can test against mock services
public class LocalTest {
  @beforeClass
  public static before() {
    //mock other services 
    //start server
    Config config = new config(...);
    Steps.setup(config) //sets up a static the static variables in my step files
  }

}

I would really like if i didn’t have to set static variables in my test because i feel like that is a bad practice. And to resolve that I would like to setup and specify what injector to use with my Runner.

P.S. If having multiple runners is also a bad practice I would be interested to here others way around this problem

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mpkorstanjecommented, Dec 12, 2017

Sounds like a good idea. A few caveats:

  1. The runtime options should not know about the details of the object factory. We are cheating a little with --junit. This should eventually be solved by creating different annotations for junit and testing.

So instead of adding a guice specific option it might be better to create an option to set environment properties. Equivalent to Javas -Dkey=value .

  1. The environment variables override cucumber options. This should be reversed and would be a major breaking change but a good one none the less.

  2. Making the properties file used configurable through a config parameters would also help e.g. --settings=cucumber. properties.

The order of precedence should be

  1. Commandline 1a. --property key=value 1b. --settings cucumber. properties
  2. cucumber. properties
  3. Environment
0reactions
lock[bot]commented, Apr 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cucumber with Guice - multiple guice injector - Stack Overflow
Solution which I've found is using custom Junit4 runner inheriting from original Cucumber runner and changing its createRuntime method.
Read more >
State - Cucumber Documentation
Whenever Cucumber needs a specific object, it uses an object factory. Cucumber has a default object factory that (in case of Guice) creates...
Read more >
Sharing state between steps in Cucumber-JVM using Guice
I annotated the constructor in GoodsSteps with @Inject . I annotated the field world with @Inject . This is a way to show...
Read more >
Package cucumber.api.guice - javadoc.io
This module allows you to use Google Guice dependency injection in your Cucumber tests. Guice comes as standard with singleton scope and 'no...
Read more >
cucumber/cucumber-jvm - Gitter
I use Cucumber JUnit runner with custom plugin defined in CucumberOptions? ... file should contain a single property key called guice.injector-source with a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found