JUnit Testing

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

Getting Started
  1. Create a new project and import BlackBoxTesting-starter.jar. This is the same process we use to import jar files.

  1. Add the BlackBoxFunctions library to your project.

    • Download BlackBoxFunctions.jar

    • Right click the project directory

    • Hover over the build path item in the list shown

    • Select Configure Build Path…​

    • Select Libraries tab

    • Select Add External JARs…​, and browse to BlackBoxFunctions.jar

    • Click Apply

  1. Add the JUnit library to Eclipse

    • Right click the project directory

    • Hover over the build path item in the list shown

    • Select Add Libraries…​ option in the sublist

    • From the list show select JUnit, click next then finish

Your directory structure should now include an additional directory called JUnit.

Description

Develop unit test for each function defined in TestingFunctions.java, to verify both that the basic behavior works and that edge cases are handled properly.

The BlackBoxCorrect class is correctly implemented, while the BlackBoxIncorrect class has bugs in edge cases. As such, all of your tests should pass for BlackBoxCorrect, but some will fail with BlackBoxIncorrect.

Implement the tests outlined in TestCases.java, and write additional tests for each function. There are 2 bugs in the incorrect version of greatestCommonDivisor, and one bug in reverseWindow. Expose all of these bugs with unit tests for completion.

Here are some example test cases you should look for:

  • For greatestCommonDivisor:

    • Negative, and 0 value inputs

    • Inputs with a GCD of 1

    • Inputs with a GCD equal to one of the values

  • For reverseWindow:

    • Input indices out of bound of the array size

    • Input indices at the bounds of the array size

    • Reversed input indices

    • Input with an empty array

    • Input with equal indices

Read the javadoc for TestingFunctions for specifications on the expected behavior of a correct implementation.

Directions

To give you an idea of what a unit test looks like, your TA will walk thorugh the implementation of some basic tests with you.

  1. Run the JUnit tests:

    • Right click TestCases

    • Select Run As from the context menu

    • Click JUnit Test

Additional Resources
Submission

Show your TA the tests you wrote, and the output of running them on both BlackBoxCorrect and BlackBoxIncorrect. You must expose three bugs for completion: 2 in greatestCommonDivisor and 1 in reverseWindow.