Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
student:junit:v4 [2018/08/14 10:11] bernstdhstudent:junit:v4 [2018/08/14 10:57] bernstdh
Line 15: Line 15:
  
  
-For each class you want to test, you must create a file named   //ClassName//Test.java where //ClassName// denotes the name   of the class being tested. So, for example, if you want to test the   class named   ''%%Atom%%'' you must create a file named ''%%AtomTest.java%%''.+For each class you want to test, you must create a file. It is common to use naming system //ClassName//Test.java where //ClassName// denotes the name   of the class being tested. So, for example, if you want to test the   class named   ''%%Atom%%'' you would create a file named ''%%AtomTest.java%%''.
  
  
Line 36: Line 36:
 import static org.junit.Assert.*; import static org.junit.Assert.*;
  
-import org.junit.Before; 
 import org.junit.Test; import org.junit.Test;
  
Line 47: Line 46:
 (Note: The ''%%import static%%'' allows you to refer to   static members in the ''%%org.junit.Assert%%'' package without having   to include the class name.) (Note: The ''%%import static%%'' allows you to refer to   static members in the ''%%org.junit.Assert%%'' package without having   to include the class name.)
    
-The file //ClassName//Test.java contains methods that can be   used to test the class defined in //ClassName//.java.  Each such   method is preceeded by an ''%%@Test%%'' annotation.  (Note: An   annotation provides information about a program but is not part of   the program. Annotations have no effect on the operation of the   program.  Instead, they are used to provide information to tools   that might use the program as input.)+The file //ClassName//Test.java contains methods that can be   used to test the class defined in //ClassName//.java.  Each such   method is preceded by an ''%%@Test%%'' annotation.  (Note: An   annotation provides information about a program but is not part of   the program. Annotations have no effect on the operation of the   program.  Instead, they are used to provide information to tools   that might use the program as input.)
  
 So, still continuing with the example   above, if the ''%%Atom%%'' class contains a ''%%public int   getAtomicNumber()%%'' method, then ''%%AtomTest.java%%''   might include the following method:  So, still continuing with the example   above, if the ''%%Atom%%'' class contains a ''%%public int   getAtomicNumber()%%'' method, then ''%%AtomTest.java%%''   might include the following method: