O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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

How it works...

A typical example of such a usage would be creating necessary tables before the first test method is run and removing them after the last method of the test class is finished. The setup/cleanup methods can also be used to create/close a database connection unless your code does it in the try-with-resources construct (refer to Chapter 12, Memory Management and Debugging). 

Here is an example of the usage of fixtures (refer to Chapter 6, Database Programming on how to set up a database for running it). Let's assume we need to test the DbRelatedMethods class:

class DbRelatedMethods{  public void updateAllTextRecordsTo(String text){    executeUpdate("update text set text = ?", text);  }  private void executeUpdate(String sql, String ...

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