Spring Cucumber and DirtiesContext

702 views
Skip to first unread message

Tuire Holappa

unread,
Mar 17, 2015, 4:15:08 AM3/17/15
to thucydid...@googlegroups.com
Hi,

Is there any source of information on how to clean the context (@DirtiesContext) between different junit test classes @RunWith(CucumberWithSerenity.class) when using net.thucydides.junit.spring.SpringIntegration?

Versions: Serenity (1.0.35), Serenity-cucumber (1.0.8) Cucumber-java (1.2.2) and Spring (3.2.8)  ?

I have tried adding the @TestExecutionListeners but that did not solve the problem:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions( plugin = { "json:target/cucumber/Ok.json" },         
          features = "classpath:features/Ok.feature")
@ContextConfiguration(locations = "/spring.xml")
@DirtiesContext
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class })
public class OkIT {
    @Rule
    public SpringIntegration springIntegration = new SpringIntegration();
}  

Best regards,
Tuire

Tony Tubbs

unread,
Feb 7, 2017, 5:01:24 PM2/7/17
to Serenity BDD Users Group
I'm looking for guidance on this too.  Doing it on the runner as the code snippet here shows doesn't seem the most correct way, as a runner could trigger multiple Features and Scenarios.  I would like to be able to use @DirtiesContext (or something equivalent) between Scenarios (similar to the method level example in JUnit when @DirtiesContext was used with @Test methods).  

This should be triggered between Scenarios or between each iteration of a Scenario Outline.

But I can't figure out where I'd put the annotation or otherwise clear context.  Please advise.
Reply all
Reply to author
Forward
0 new messages