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 to do it...

To accomplish this, you can dedicate a method that does the setup by writing a @Before annotation in front of it. The corresponding cleaning method is identified by the @After annotation. Similar class-level methods are annotated by @BeforeClass and @AfterClassHere is a quick demo of this. Add the following methods:

public class DatabaseRelatedTest {  @BeforeClass  public static void setupForTheClass(){    System.out.println("setupForTheClass() is called");  }  @AfterClass  public static void cleanUpAfterTheClass(){    System.out.println("cleanAfterClass() is called");  }  @Before  public void setupForEachMethod(){    System.out.println("setupForEachMethod() is called");  }  @After  public void cleanUpAfterEachMethod(){    System.out.println( ...

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