CodesJava

Easy learning with example program codes

JUnit tutorial


Testing:

Testing is the process of checking an application that it is working as expected. Working as expected means for a known input it must give the expected output. In other words testing is a process of verification and validation.

Unit testing:

Unit testing is the testing of an individual unit (class/method) or group of related units.

Types of unit testing:

1. Manual testing
2. Automated testing

Manual testing:

Manual testing is the process of executing a test case without any tool support.

Automated testing:

Automated testing is the process of executing a test case with any tool support.

JUnit:

JUnit is an open-source unit testing framework for java programmers. It is only used for unit testing. Integration testing is done by TestNG.

Unit test case:

Unit test case is part of code which executes to check that another part of the code works as expected.

Note: We have to write two test cases for every requirement/sub-requirement one positive and one negative.

Annotations for Junit testing:

1. @Test: It is used to specify the test method.

2. @BeforeClass: It is used to specify that method will be called only once, before starting all the test cases.

3. @AfterClass: It is used to specify that method will be called only once, after finishing all the test cases.

4. @Before: It is used to specify that method will be called before each test case.

5. @After: It is used to specify that method will be called after each test case.

6. @Ignore: It is used to ignore the test case.

Assert class:

JUnit provides the Assert class to check the certain conditions. Assert class methods compare the output value to the expected value.

Commonly used methods of Assert class:

1. assertTrue(boolean condition): It assert that the specified boolean condition is true.

2. assertFalse(boolean condition): It assert that the specified boolean condition is false.

3. assertNull(Object obj): It assert that the specified object is null.

4. assertNotNull(Object obj): It assert that the specified object is not null.

5. assertEquals(Object expected, Object actual): It assert that two objects are equal.

6. assertSame(Object expected, Object actual): It assert that two objects refer to the same object.

 

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.

 

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki