[cucumber-spring] Cucumber glue scope not registering.

1,459 views
Skip to first unread message

Chris Kelley

unread,
Oct 8, 2014, 2:55:52 PM10/8/14
to cu...@googlegroups.com
Hello, 
I just started working on upgrading my test framework from cucumber-spring 1.1.2 to cucumber-spring 1.2.0-SNAPSHOT. I have almost everythign functioning again, except for a "TestDataHolder" class that is annotated with @Scope("cucumber-glue"), so that the any data that is in that class is flushed after each scenario run. 
This fails at runtime with the message:

Caused by: java.lang.IllegalStateException: No Scope registered for scope 'cucumber-glue'

java.lang.IllegalStateException: No Scope registered for scope 'cucumber-glue'
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)

At one point, I believe there was a workaround to include the following in application context: 

        import resource="classpath:cucumber/runtime/java/spring/cucumber-glue.xml"/

But that doesn't seem to work anymore (that file doesn't exist). 

I've tried to include the TestDataHolder bean in cucumber.xml, but it still complains. 
I also tried to use @DirtiesContext, but that doesn't flush the test object either, because, i assume it's not in the correct scope. 

Any suggestions would be greatly appreciated.  
 
Thanks, 
Chris



Chris Kelley

unread,
Oct 8, 2014, 6:39:02 PM10/8/14
to cu...@googlegroups.com


On Wednesday, October 8, 2014 2:55:52 PM UTC-4, Chris Kelley wrote:
Hello, 
I just started working on upgrading my test framework from cucumber-spring 1.1.2 to cucumber-spring 1.2.0-SNAPSHOT. I have almost everythign functioning again, except for a "TestDataHolder" class that is annotated with @Scope("cucumber-glue"), so that the any data that is in that class is flushed after each scenario run. 
This fails at runtime with the message:

Caused by: java.lang.IllegalStateException: No Scope registered for scope 'cucumber-glue'


After some debugging, I figured it out, and Scope("cucumber-glue") is working as expected. Below is the explanation for future reference

I previously had classes that included the @Scope'd bean, that were out of scope for some reason or another. In 1.1.2 cucumber-spring didn't complain about this, but now its complaining. I resolved it by adding the out of scope classes to cucumber-glue scope.

Failed Scenario:
++++++++++++++++++++++++++++++++++
@Scope("cucumber-glue")
@Component
class TestDataHolder {} 

@Compenent
class OutOfScopeClass {

  @Autowired
  TestDataHolder testDataHolder

}

Result: java.lang.IllegalStateException: No Scope registered for scope 'cucumber-glue' 
+++++++++++++++++++++++++++++++++++++++++++++


 Fix:
+++++++++++++++++++++++++++++++++++++
@Scope("cucumber-glue")
class OutOfScopeClass {

  @Autowired
  TestDataHolder testDataHolder




But that doesn't seem to work anymore (that file doesn't exist). 

I've tried to include the TestDataHolder bean in cucumber.xml, but it still complains. 
I also tried to use @DirtiesContext, but that doesn't flush the test object either, because, i assume it's not in the correct scope. 


I also played around with @DirtiesContext. I got this functioning, but is not feasible for me because there are beans in scope (for example, a selenium service/driver) that I wanted to persist throughout the test run. 
By adding @DirtiesContext, this service would be re-initialized for each scenario. 

Paolo Ambrosio

unread,
Oct 9, 2014, 2:33:33 AM10/9/14
to cu...@googlegroups.com
I believe that is what @DirtiesContext is meant to do. What are you
trying to achieve by using it? I can't see how it would be needed in
functional testing to be honest.

Paolo

>> Any suggestions would be greatly appreciated.
>>
>> Thanks,
>> Chris
>>
>>
>>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Chris Kelley

unread,
Oct 9, 2014, 10:02:28 AM10/9/14
to cu...@googlegroups.com


On Thursday, October 9, 2014 2:33:33 AM UTC-4, Paolo Ambrosio wrote:

> I also played around with @DirtiesContext. I got this functioning, but is
> not feasible for me because there are beans in scope (for example, a
> selenium service/driver) that I wanted to persist throughout the test run.
> By adding @DirtiesContext, this service would be re-initialized for each
> scenario.

I believe that is what @DirtiesContext is meant to do. What are you
trying to achieve by using it? I can't see how it would be needed in
functional testing to be honest.

Paolo


 
Yep. @DirtiesContext is working as expected. I was just attempting to workaround my issues with Cucumber-glue scope. I thought using @DirtiesContext would be the "correct" way of resetting objects in test. But it won't work within my framework right now. It would take a lot of refactoring to use @DirtiesContext. Now that I have @Scope("cucumber-glue") working i don't need @DirtiesContext. It did expose some bugs in my code, though. 


Reply all
Reply to author
Forward
0 new messages