JUnit

What is JUnit and how it is used?

Questions by sunil79

Showing Answers 1 - 9 of 9 Answers

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 package junit.framework for JUnit 3.8 and earlier, and under package org.junit for JUnit 4 and later.

  Was this answer useful?  Yes

Code
  1. import org.junit.*;

  2.  

  3. public class TestFoobar {

  4.     @BeforeClass

  5.     public static void setUpClass() throws Exception {

  6.         // Code executed before the first test method      

  7.     }

  8.  

  9.     @Before

  10.     public void setUp() throws Exception {

  11.         // Code executed before each test    

  12.     }

  13.  

  14.     @Test

  15.     public void testOneThing() {

  16.         // Code that tests one thing

  17.     }

  18.  

  19.     @Test

  20.     public void testAnotherThing() {

  21.         // Code that tests another thing

  22.     }

  23.  

  24.     @Test

  25.     public void testSomethingElse() {

  26.         // Code that tests something else

  27.     }

  28.  

  29.     @After

  30.     public void tearDown() throws Exception {

  31.         // Code executed after each test  

  32.     }

  33.  

  34.     @AfterClass

  35.     public static void tearDownClass() throws Exception {

  36.         // Code executed after the last test method

  37.     }

  38. }

  Was this answer useful?  Yes

Satendra Kumar

  • Nov 10th, 2014
 

JUnit is primary testing which is done by programmer to ensure that my code is a quality code.
we can used unit testing by creating test cases ........

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions