What Is Junit ?
What Is Junit ?
JUnit is a unit testing framework for Java programming language. It plays a crucial
role test-driven development, and is a family of unit testing frameworks
collectively known as xUnit.
JUnit promotes the idea of "first testing then coding", which emphasizes on
setting up the test data for a piece of code that can be tested first and then
implemented. This approach is like "test a little, code a little, test a little, code a
little." It increases the productivity of the programmer and the stability of
program code, which in turn reduces the stress on the programmer and the time
spent on debugging.
Features of JUnit
JUnit is an open source framework, which is used for writing and running
tests.
Provides annotations to identify test methods.
Provides assertions for testing expected results.
Provides test runners for running test
JUnit tests allow you to write codes faster, which increases quality.
JUnit is elegantly simple. It is less complex and takes less time.
JUnit tests can be run automatically and they check their own results and
provide immediate feedback. There's no need to manually comb through a
report of test results.
JUnit tests can be organized into test suites containing test cases and even
other test suites.
JUnit shows test progress in a bar that is green if the test is running
smoothly, and it turns red when a test fails.
Downloading :
You can download JUnit 5 from http://www.junit.org/index.htm in the
zipped format
Unzip the JUnit 5 zip file
Add junit-5.jar to the CLASSPATH
Test1.java
package test1;
/**
* @author LENOVO
*/
return a+b;
return c + e;
Test1IT.java
package test1;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* @author LENOVO
*/
public Test1IT() {
@BeforeClass
}
@AfterClass
@Before
@After
/**
*/
@Test
int a = 2;
int b = 2;
/**
*/
@Test
assertEquals("rohitrk",result);