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-spring with @Configuration class fail with @Scope("cucumber-glue")

See original GitHub issue

They way the cucumber-glue scope get registered won’t work when you’re using some of these scoped components in your non-scoped components declared in your configuration.

For example:

public interface ComponentA{}

@Component
public class DomainComponent{

    @Autowired
    private ComponentA beingInjected;
}

@Configuration
public class MyTestConfiguration{
    @Bean
    @Scope("cucumber-glue")
    public ComponentA componentA(){
        return Mockito.mock(ComponentA.class);
    }
}

@ContextConfiguration(classes=MyTestConfiguration.class)
public class MyGlueCode{

    @Autowired
    private DomainComponent domainComponent;

}

This is because the way the scope currently get registered, we need the ApplicationContext to add the scope into it.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
JSlaincommented, Mar 2, 2016

Yes there is. You need to register the GlueScope directly in your configuration, like this:

    @Bean
    public CustomScopeConfigurer glueScopeConfigurer(){
        CustomScopeConfigurer toReturn = new CustomScopeConfigurer();

        toReturn.addScope("cucumber-glue", new GlueCodeScope());

        return toReturn;
    }

However, you can’t do it directly since GlueCodeScope is package visible. The workaround is to create a new class with the @Configuration annotation in the same package as GlueCodeScope (which is cucumber.runtime.java.spring). Register the scope in it with the code above.

Then in your glue code, you must use that configuration in addition to your own.

The pull request i made does exactly this, except your don’t have to add it manually to your config, it’s done magically with ASM. I think it’s a bad thing, but haven’t found another way doing it; except maybe modifying something else directly in spring.

0reactions
lock[bot]commented, Nov 2, 2018

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 Spring and class configuration - Stack Overflow
Classes with no constructor parameters are annotated with @Component and @Scope("cucumber-glue") annotation so bean creation can be removed from ...
Read more >
Spring – Cucumber Spring and class configuration - iTecNote
I'm using Spring 4.2.4, all cucumber dependencies in version 1.2.4. Config: @Configuration public class AppConfig { @Bean @Scope("cucumber-glue") ...
Read more >
[cucumber-spring] Cucumber glue scope not registering.
This fails at runtime with the message: Caused by: java.lang.IllegalStateException: No Scope registered for scope 'cucumber-glue'. java.lang.
Read more >
Cucumber Tests in Spring Boot with Dependency Injection
This guide shows you how to configure Dependency Injection for your Cucumber tests in Spring Boot.
Read more >
IntelliJ IDEA - Run/Debug configuration: Cucumber Java
The Cucumber run/debug configuration enables you to run features or scenarios via the cucumber.cli.main class. For information on how to create and run ......
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