Sunday, December 09, 2012

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) { … }
  }

No comments: