[JVM Spring] How to use @DirtiesContext to reset test data between features

1,954 views
Skip to first unread message

Marcel Overdijk

unread,
Oct 7, 2014, 5:45:18 AM10/7/14
to cu...@googlegroups.com
I'm using Spring Boot and would like to convert my Spring MockMvc Java tests to Cucumber.

We are already using Cucumber to run automated AT test using Selenium.

Between each feature I want to reset the database.
With the Java tests this works using the @DirtiesContext annotation.

I've added this annotation to the Stepdefs classes but it has no effect.

Any ideas?

Björn Rasmusson

unread,
Oct 7, 2014, 4:34:42 PM10/7/14
to cu...@googlegroups.com
Hi,

What version of Cucumber-JVM are you using? In v1.2.0-SNAPSHOT some spring issues of previous version has been fixed.

If one of the stepdef classes have both a @ContextConfiguration and a @DirtiesContext (like this), the spring-context should be reloaded between each scenario.
How that works together with Spring Boot, I do not know.

Best Regards
Björn



Marcel Overdijk

unread,
Oct 8, 2014, 1:11:28 AM10/8/14
to cu...@googlegroups.com
I was using 1.1.8 and it works now.

My in memory HSQLDB database was not closing/resetting between scenario's.
I fixed this by adding ;shutdown=true to the jdb connection url.
The strange thing is that I saw different behaviour when I run ordinary junit tests.

Btw do you know which kind of issues are fixed in 1.2.0 snapshot?

Marcel Overdijk

unread,
Oct 8, 2014, 1:32:41 AM10/8/14
to cu...@googlegroups.com
I think btw the different behaviour between using cucumber and ordinary junit tests is that the org.springframework.transaction.annotation.Transactional annotation works for junit tests but not for cucumber.

Or should I do something special to be able to use @Transactional on my stepdef classes?


On Tuesday, October 7, 2014 10:34:42 PM UTC+2, Björn Rasmusson wrote:

Björn Rasmusson

unread,
Oct 8, 2014, 7:53:11 AM10/8/14
to cu...@googlegroups.com
Marcel Overdijk wrote:
I was using 1.1.8 and it works now.

My in memory HSQLDB database was not closing/resetting between scenario's.
I fixed this by adding ;shutdown=true to the jdb connection url.
The strange thing is that I saw different behaviour when I run ordinary junit tests.

Btw do you know which kind of issues are fixed in 1.2.0 snapshot?
Hi,

Please use interleaved answers according to http://cukes.info/posting-rules.html.
issues fixed in v1.2-SNAPSHOT (mainly in #711):
- autowiring one stepdef class into another
- the @txn transaction support, using the @txn annotation in a feature file executes the scenarios in a transaction.
- the @ContextConfiguration annotation not neede on every stepdef class.
- fallback to use a cucumber.xml configuration file from the classpath if no @ContextConfiguration is found.

Best Regards
Björn

Marcel Overdijk

unread,
Oct 8, 2014, 2:38:17 PM10/8/14
to cu...@googlegroups.com


On Wednesday, October 8, 2014 1:53:11 PM UTC+2, Björn Rasmusson wrote:
Marcel Overdijk wrote:
I was using 1.1.8 and it works now.

My in memory HSQLDB database was not closing/resetting between scenario's.
I fixed this by adding ;shutdown=true to the jdb connection url.
The strange thing is that I saw different behaviour when I run ordinary junit tests.

Btw do you know which kind of issues are fixed in 1.2.0 snapshot?
Hi,

Please use interleaved answers according to http://cukes.info/posting-rules.html.
issues fixed in v1.2-SNAPSHOT (mainly in #711):
- autowiring one stepdef class into another
- the @txn transaction support, using the @txn annotation in a feature file executes the scenarios in a transaction.
- the @ContextConfiguration annotation not neede on every stepdef class.
- fallback to use a cucumber.xml configuration file from the classpath if no @ContextConfiguration is found.

Best Regards
Björn


Thanks Bjorn.
I switched to 1.2.0-SNAPSHOT. Do you know the roadmap for 1.2.0? Are there any planned milestones releases?
Reply all
Reply to author
Forward
0 new messages