Basic annotations of JUnit

JUnit has some basic and important annotations, such as the following:

  • The @BeforeClass: This runs once before any test functions in the class. In this function, you can connect the database or connection pool. This function has to be a static method.
  • The @AfterClass: This runs once after any test functions in the class. In this function, you can close the database connection and cleanup.
  • The @Before: This can run before @Test annotated functions. Here you create some objects and share to all @Test annotated testing functions.
  • The @After: This can run after @Test annotated functions. Here, you modify or clean the objects and share to all @Test annotated testing functions.
  • The @Test: This annotated function is the test function.

Now we'll look at an example of how to test a project with JUnit. Here, you can learn about the life cycle of the testing annotations and the use of these annotations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.174.0