JUnit Testing

The TA will walk through project setup (Getting Started) at the beginning of the recitation.

The goal of this lab is to demonstrate White Box testing, where you have access to the source code and write tests to ensure complete code coverage.

Getting Started
  1. Use your project directory from the previous lab for this recitation. You will not have to import anything here.

    • Create a new class titled MyFunctions which implements the TestingFunctions interface.

    • In TestCases.java, comment out the lines initializing functions as BlackBoxCorrect and BlackBoxIncorrect, and create a new line which initializes it as an object of MyFunctions.

  1. Install EclEmma for Code Coverage

    • Follow the instructions for Option 2 on the EclEmma installation page.

    • Restart Eclipse

    • Run tests with code coverage using the new Coverage Mode button next to the Run Mode and Debug Mode buttons.

Description

Implement the functions greatestCommonDivisor and reverseWindow in MyFunctions.java. Use the unit tests in TestCases.java to verify that you have implemented the functions correctly. You may find it helpful to write additional tests before you begin writing your code to catch any error cases. All of your tests should pass.

Once you have implemented your functions, run the tests with code coverage (process for this described below). Lines which are tested will appear green, lines which are not tested will appear red, and lines with conditional statements where not all conditions are tested are marked yellow.

Write additonal tests in TestCases.java until all lines in MyFunctions.java are covered by testing, and appear green or yellow, with no red lines. Do not worry about code coverage in TestCases.java.

Directions
  1. Run the JUnit tests with code coverage:

    • Right click TestCases

    • Select Coverage As from the context menu

    • Click JUnit Test

    • Click on MyFunctions.java to see the code coverage.

Additional Resources
Submission

Show your TA your MyFunctions.java file with complete code coverage.