Sunday, December 09, 2012

JUnit Step By Step (Basic Introduction) Part-1.1


Prerequisites:
A.) Windows / Ubuntu machine :)
B.) Eclipse IDE (I am using Eclipse Platform Version: 4.2.1-JUNO) or any IDE which support   
      JUnit. You can search google in this regard "IDE supported JUnit framework"
C.) Knowledge of Java language. 

Steps:
1.) Run eclipse and install JUnit plugin if its not pre-install with your IDE. 

2.) http://www.junit.org/ (From this location you can also download JUnit)


3.) Download: junit4.11.zip — Complete ZIP file

4.) For more information regarding JUnit: https://github.com/kentbeck/junit/wiki

5.) JUnit Mind -Map regarding its packages and there dependencies:
     



    

Java’s Unit Testing Framework basic layout in Eclipse IDE



  1.) Create the class that you will want to test.
        For example: Class name = Bug

  2.) Build the test class - with the needed imports and extensions for   
        JUnit.

   2.1) We extend from junit.framework.TestCase.
   2.2)We name the test methods with the prefix “test”.

  3.) Code the actual test cases.
   3.1) We validate conditions using one of the several assert methods.
   
   import junit.framework.*; //JUnit compulsory component added)//
   
   public class TestFailure extends TestCase 

  {

   public void testSquareRootException() 
  {
   try 
  {
  SquareRoot.sqrt(-4, 1);
  fail("Should raise an exception");
  }
  catch (Exception success) { … }
  }