Showing posts with label Junit. Show all posts
Showing posts with label Junit. Show all posts

Tuesday, September 21, 2021

@BeforeClass,@AfterClass,@Before and @After annotation in Junit ?

 @BeforeClass:  This is annotation is used in that method when there need such situation to do some prior works when test class is loaded in memory. Ex: DB connection establishment.

@Before: This annotation is used when need to do some works before @Test is execute.

@After:    This annotation is used when need to do some works after @Test is execute.

@AfterClass: Is called and execute after all the operation has done in the Test class.

@BeforeClass and @AfterClass runs for once in every test class

Monday, September 20, 2021

What is Junit and how it works?

 Junit is a unit testing framework for java programing language. It is necessary for test driven development.

 To include Junit in project create another source folder and create a class for Junit testing .

Then Junit jars will include in classpath.

When runs a Junit test it first create the instance of the Junit class then call the method annotated with @Test.

Keep in mind-Absence of fail() it is success in Junit.

Testing controller

------Controller------------- @RestController @RequestMapping("/items") public class ItemController {     private final ItemServic...