Index of /~billard/se/cs4320/ex11

      Name                    Last modified       Size  Description

[DIR] Parent Directory 20-Apr-2008 08:49 - [   ] AllTests.class 19-May-2009 09:03 1k [TXT] AllTests.java 19-May-2009 09:03 1k [   ] MyCalendar.class 19-May-2009 09:03 1k [TXT] MyCalendar.java 19-May-2009 09:03 1k [   ] MyCalendarTest.class 19-May-2009 09:03 1k [TXT] MyCalendarTest.java 19-May-2009 09:03 1k [   ] MyMath.class 19-May-2009 09:03 1k [TXT] MyMath.java 19-May-2009 09:03 1k [   ] MyMathTest.class 19-May-2009 09:03 1k [TXT] MyMathTest.java 19-May-2009 09:03 1k [   ] Stack.class 19-May-2009 09:03 1k [TXT] Stack.java 19-May-2009 09:03 1k [   ] StackTest.class 19-May-2009 09:03 1k [TXT] StackTest.java 19-May-2009 09:03 1k [   ] VectorTest.class 19-May-2009 09:03 1k [TXT] VectorTest.java 19-May-2009 09:03 1k [TXT] examples.txt 19-May-2009 09:03 2k [   ] print.bat 19-May-2009 09:03 1k [TXT] setpaths 19-May-2009 09:03 1k


CS 4320 Software Testing and QA: Ex11 JUNIT TEST
================================================

Platform: UNIX

Given: source code

Goal: Perform unit testing on Java objects with JUnit.
      This is a popular method for developing and testing
      object-oriented code. In fact, some engineers design
      the test cases first, then develop the source code.
      JUnit provides a "harness" or framework to run the 
      collection of all test cases, and reports any errors found.  
      For those engineers who develop the test cases first,
      then of course there would be many errors since the
      code doesn't do anything yet. But as progress is made
      on the code, then the errors become fewer. When is the
      development completed - when all the errors disappear.

a. For reference, see:

   http://junit.sourceforge.net/
   http://junit.sourceforge.net/doc/cookbook/cookbook.htm
   http://junit.sourceforge.net/doc/cookstour/cookstour.htm

   % more /usr/local/vcs/junit/framework/*.java

   This implementation has 5 design patterns: 
   Command, Template, Collecting Parameter, Pluggable Selector, Composite
   In this course, we do not really get into design patterns, but
   CS 4311 Software Engineering II really does.

b. % more MyCalendar.java
   % more MyCalendarTest.java
   % more AllTests.java
   % source setpaths
   % java AllTests 

  
The test cases are organized in a hierarchical fashion using
the composite design pattern:

            ----AllTests----
           /                \
          A                  B
         / \                / \
   Vector   Stack  MyCalendar MyMath
   Test     Test   Test       Test

AllTests calls its children (A, B) to perform all of their test
cases. They, in turn, call all of their children. And so on
until the leaf nodes where the actual test cases reside. 

If you'd like to more about the composite pattern:

  http://www.sci.csueastbay.edu/~billard/cs4311/node20.html

Now back to the java code:

  Note1: assertEquals/assertTrue are similar to the assertions in 
         Proof of Correctness, especially the PRE- and POST-CONDITIONS
         of the function calls. They are also similar to the expected
         return values in the Cyclometric Complexity white box all paths
         code coverage.
   
  Note2: Boundary-Value Analysis (BVA) black box test for MyCalendar would 
         have tested 0,1,12,13 but not 9 and so would have missed the failure.

  Note3: "Failures" are potential faults that can be anticipated.
         "Errors" are other unanticipated exceptions that occur.

c. % more VectorTest.java
   % java AllTests

   Multiple methods are tested and multiple assertions are maintained.

d. % more MyMath.java
   % more MyMathTest.java

   Edit MyMathTest and fill-in two test cases along with assertEquals:

   testZero   : 5^0
   testNonZero: 5^2

   There is one predicate, hence, the Cyclometric Complexity is 2, which implies
   there are two paths to complete all path code coverage. One path (testZero)
   should not enter the loop at all. The second path (testNonZero) enters the loop.

   [IN THIS SESSION HAVE YOU DONE: source setpaths]

   % javac MyMathTest.java
   % java AllTests

   But the result of the second test is a failure. Find and fix the bug in pow
   and re-run. Now, perform a Proof of Correctness on the code.

   Junit can be used for unit testing in:
   
   i. white box test: examine code for paths to establish inputs/outputs
  ii. black box test: examine specification to establish inputs/outputs
 iii. regression test: run the TestSuite after any modifications/enhancements
  iv. development: write TestSuite for all methods before coding. When
        the TestSuite runs successfully, development is over.
   v. bug reporting: write TestSuite to demonstrate a reported bug, then
        fix the bug. 

e. % more Stack.java
   % more StackTest.java

   Edit StackTest and fill-in the stackTest method such that:

   i. all methods of the Stack class are tested within the stackTest method.
  ii. multiple assertTrue/Equals are stated. Be sure to verify the LIFO property. 
        (try for 7 - see VectorTest as example. Hint: fill-up and empty the stack).
   
   [IN THIS SESSION HAVE YOU DONE: source setpaths]
   
   % javac StackTest.java
   % java AllTests

   ONLINE students: submit 

     MyMathTest.java (with two assertEquals)
     MyMath.java (with a bug fix on pow, and also a Proof of Correctness)
     StackTest.java (with hopefully 7 good assertTrues/Equals)

f. project notebook (see print.bat):

   README
   MyCalendar.java
   MyCalendarTest.java
   AllTests.java  
   VectorTest.java
   MyMath.java
   MyMathTest.java
   Stack.java
   StackTest.java