JUnit - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

JUnit Framework

JUnit Framework

shape Introduction

This chapter demonstrate about the JUnit Frame Work which is developing the test cases for the Java projects and following are the concepts covered in this chapter.
  • How to define a test in JUnit
  • JUnit naming conversions
  • Example JUnit test

How to define a test in JUnit

shape Description

In order to define a test in JUnit initially user need to develop the project and then create a test case for developed project. Following are the steps to demonstrate a test in JUnit Framework.

shape Step 1

In order to create the Test case initially user need to create the test project then right click on the project and Select New - > then click JUnit Test Case as show in below image.

shape Step 2

Now a window get explored named as New JUnit Test Case then enter the test case and click on the Finish button to complete the process.

JUnit naming conversions

shape Description

Naming conversions are defined as the naming rules of some programming languages which are applicable for the JUnit also has some set of rules to form the names of the Classes, Variables, Functions.

Example JUnit test

shape Description

User need to develop a Java project, assume the project name to be as ProteinTracker, then user need to add a test method to that project some thing like ProteinTrackerTest. The code below demonstrate the test method for the created project. [c] import static org.junit.Assert.*; import org.junit.Test; public class helloJUnitTest { @Test public void test() { //fail("Not yet implemented"); } }[/c] Once done with the test method now its time to run the test method. The below steps demonstrate how to run the JUnit tests. Created project test method can be runned as follows, Right click on Test -> Run As -> JUnit Test The test case produces the output in green color which indicates as successful as shown in below image.

Summary

shape Key Points

  • JUnit Framework - Software Experts must follows the naming conversions.
  • JUnit Framework - While creating the Test project Add source project to the test project.
  • JUnit Framework - JUnit test has different test cases.