JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks which is collectively known as xUnit that originated with SUnit.
JUnit is linked as a JAR at compile-time; the framework resides under packages junit.framework for JUnit 3.8 and earlier and under org.junit for JUnit 4 and later.
import org.junit.*; public class TestFoobar{ @BeforeClass public static void setUpClass() throws Exception { // Code executed before the first test method } @Before public void setUp() throws Exception { // Code executed before each test } @Test public void testOneThing() { // Code that tests one thing } @Test public void testAnotherThing() { // Code that tests another thing } @Test public void testSomethingElse() { // Code that tests something else } @After public void tearDown() throws Exception { // Code executed after each test } @AfterClass public static void tearDownClass() throws Exception { // Code executed after the last test method } }