Friday, November 17, 2017

JUnit Tests Basics and how to do unit testing in java

Junit is one of the most popular unit testing framework for java developer Junit has been important in Test driven Implementation.

Below are the Annotation which are available in Junit 4

@Test Identifies a method as a test method
@Before Executed before each test. It is used to prepare the test environment (e.g read input data , initialize the class)
@After Executed after each test. It is used to cleanup the test environment.It can also save menory by cleaning up expensive memory structures.
@BeforeClass Executed once, before the start of all the tests. Methods marked with this annotation need to be definedas static to work with Junit.
@AfterClass Executed once after all the tests have been finished. Methods annotated with this annotation need to be defined static to work with Junit.
@Ignore Marks that the test should be disabled.
@Test(expected =Exception.class) Fails if the method does throw the named exception.
@Test(timeout =10) Fails if the method takes longer than 100 milliseconds.

Below is the Program where we are using the JUnit testing Basics

Thanks for reading


Post a Comment