Home > OS >  Cucumber configuration error in IntelliJ: Please annotate a glue class with some context configurati
Cucumber configuration error in IntelliJ: Please annotate a glue class with some context configurati

Time:01-04

So I recently started working on Cucumber and have been facing this issue.

This is the hierarchy of my module enter image description here

As you can see this is submodule in my Spring Boot application (AcceptanceTests), so there are no main methods in it.

This is my CucumberSpringContextConfiguration class

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@CucumberContextConfiguration
public class CucumberSpringContextConfiguration {
}

This is my CucumberIntegrationTest class

@RunWith(Cucumber.class)
@CucumberOptions(
  features = "src\test\resources\feature",       
  plugin = {"pretty", "html:target\\cucumber"}, 
  glue = "com.#####.########.cucumberspringboot.cucumberglue"
)
public class CucumberIntegrationTest {}

I tried running this code with a main class (src/main/java),the code compiled successfully. But since that is not my requirement I removed it and now I am getting below error -

SEVERE: Exception while executing pickle
java.util.concurrent.ExecutionException:
io.cucumber.core.backend.CucumberBackendException: Please annotate a
glue class with some context configuration.

  For example:

     @CucumberContextConfiguration    
     @SpringBootTest(classes = TestConfig.class)    
     public class CucumberSpringConfiguration { } 

  Or: 
  
     @CucumberContextConfiguration
     @ContextConfiguration( ... )   
     public class CucumberSpringConfiguration { }   
  
  at java.util.concurrent.FutureTask.report(FutureTask.java:122)
  at java.util.concurrent.FutureTask.get(FutureTask.java:192)
  at io.cucumber.core.runtime.Runtime.run(Runtime.java:93)
  at io.cucumber.core.cli.Main.run(Main.java:92) 
  at io.cucumber.core.cli.Main.main(Main.java:34) 
Caused by: io.cucumber.core.backend.CucumberBackendException: 
  Please annotate a glue class with some context configuration.

Please suggest how to achieve this without using main class.

CodePudding user response:

io.cucumber.core.cli.Main.run(Main.java:92) at io.cucumber.core.cli.Main.main(Main.java:34) 

This part of the stacktrace shows you are using the Cucumber CLI rather than CucumberIntegrationTest. So you are probably running your feature file through IDEA. Presumably you clicked the green play icon in the gutter of a feature file.

Unfortunately Intelij IDEA makes some assumptions and bad guesses. If you look at the run configuration that was created you'll see that there is a command line with --glue argument that probably points at features. You'll have to change this manually.

It is currently unnecessary to guess the --glue argument and I have already asked the team behind Intelij IDEA to fix this at IDEA-243074 but the issue has gotten zero attention so far. You can upvote it, maybe something happens.

You can also avoid this problem by putting your feature files in a different location e.g. src/test/resources/com/#####/########/cucumberspringboot. Becaus this is the parent package of cucumberglue Ingelij IDEA is less likely to mess things up.

Also note: you are currently using JUnit 4 to run Cucumber. Spring Boot prefers using JUnit 5. You should use the Cucumber JUnit Platform Engine. You can find a minimal example here.

  • Related