O'Reilly logo

The Cucumber for Java Book by Seb Rose, Matt Wynne, Aslak Hellesoy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cleaning the Database with Truncation

Truncating the database before each scenario is a brute-force technique, and the main drawback is that it’s generally slower than rolling back a transaction. This is why the transactional approach is typically preferable if you can get away with it. The advantage of truncation is that it’s a cleaning strategy that works reliably when we have more than one database connection, since no transactions are used. Let’s modify our cleaning strategy and see how it compares. This is a simple change in our KnowsTheDomain class, shown in the following code.

databases/07/src/test/java/support/KnowsTheDomain.java
 
public​ KnowsTheDomain() {
 
if​ (!Base.hasConnection()){
 
Base.open(
 
"com.mysql.jdbc.Driver"​,

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required