JUnit 5

Objectives
  1. Set up your project with JUnit 5.

  2. Get started with creating your own unit tests.

Description

The JAR file you downloaded for P6 should already have the two unit testing classes within it. This classes are named "P6_Unit_Testing_MyArrayList" and "P6_Unit_Testing_MyLinkedList".

Initial Error Messages

The first step should be to see if the JUnit 5 library is included in the project. If it is not, go to the 'Adding JUnit 5 library' section below.

Adding JUnit 5 Library

To add the JUnit 5 library to the project:

  • Right click on the project folder.


    Add Library 1

  • Hover over 'Build Path...'


    Add Library 2

  • Click 'Add Libraries...'


    Add Library 3

  • Select 'JUnit 5' and save.


    Add Library 4

Unit Testing

Not all of the unit tests have been included within the unit testing class. It is your job to add more tests. Make sure to test all paths to be sure your code is implemented correctly.

When creating unit tests, it may not seem intuitive but, try to write the code for your tests before writing the actual functional code.

  • This will help you understand what your code should actually do before you start getting into a flow of writing.
  • When programming, it is easy to fall into the cycle of writing code, finding a bug, bandaging the code, and repeat. Unit testing when done correctly will allow you to organize what task needs to be done and how to do it correctly.

Note
Here are some tips to remember when creating unit tests for this project:
  • Don't have too many assert statement in a single test.
  • Testing how the program handles expected inputs is necessary, but testing how the program handles unexpected inputs is also important.