To get experience using junit to create and run unit tests.
For this assignment, you will be adding JUnit unit tests to this Student class. This way, the methods of the class can be tested automatically.
addCourse
method. Your test
should create three student objects and give them various classes
by calling addCourse
. For each one, you should use
assertEquals
to verify that their GPA and credits are correct.
For the GPA, pass a delta value into assertEquals
,
since floating-point comparisons may not be exact. Be sure to include the
edge case where a student fails a course, making sure it's not added to
their credits.canGraduate
. You should create four students
and give them a GPA and credits to test each of the four possible states:
(neither sufficient, sufficient GPA but not credits, sufficient credits but not GPA,
both sufficient). Use assertEquals
to make sure each has the right
outcome.getYear
. Make four different students with each level
of credits and use assertEquals
to verify that they are given the correct year.Make sure that you run the tests. As the class is, all of your tests should all pass.
Verify that introducing a bug into the Student class causes your tests to fail. For example,
if you comment out the line in addCourse
which computes the GPA, or otherwise
change the code such that its answers are not right, your tests should begin to fail.
For this lab, you should submit the StudentTest.java file with your unit testing for the Student class.
Copyright © 2024 Ian Finlayson | Licensed under a Creative Commons BY-NC-SA 4.0 License.