Home CPSC 330

JUnit Exercise


To get experience using the JUnit testing library.


For this lab, you will add a JUnit test for an existing class, the Line class given here.

Your test should test each of the methods in the class.


  1. Download the Line.java file.
  2. Create a file called LineTest.java.
  3. Create tests for the getSlope, getDistance and parallelTo methods.
  4. Because of rounding errors, it is bad practice to test double values for exact equality. To get around this, you can pass a small value (such as .0001) to assertEquals to be used as a delta.
  5. Each test should contain three different test cases.
  6. Copy the example TestRunner.java program (change the name of the test class).


When your program is done, email the code to ifinlay@umw.edu.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.