February 2015
Intermediate to advanced
338 pages
8h 16m
English
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", |
| | |
Read now
Unlock full access