⌛⌛ JUnit tests for course attainment¶
Place your code into the subdirectory
Round11/junitattainment/src/test/java/fi/tuni/prog3/junitattainment. Fetch task material from
This task concerns implementing JUnit tests for a class
Attainment that represents course
attainments. The class is quite similar to what has been used already in some previous tasks.
Attainment is expected to have the following properties:
Belongs into the package
Implements the interface
The interface member function
compareTocompares primarily student numbers and secondarily course codes. These comparisons are done with the
compareTofunction of the
A public constructor
Attainment(String courseCode, String studentNumber, int grade).
Attainmentobject with the given course code, student number and grade.
Throws an exception of type
null, or if
gradedoes not belong to the interval 0…5.
Public member functions
Return the values corresponding to their names, ie. the course code, student number and grade.
A public member function
Returns a string of form “
courseCode studentNumber grade” (note that now there is no newline).
Implement JUnit tests that test the following aspects of the class
Attainmentobject has been constructed, are the values returned by
getGrade()equal to the values that were provided to the constructor?
Does the constructor throw an exception of type
IllegalArgumentExceptionif it receives an illegal parameter?
toStringreturn a string with the expected form?
compareTowork as expected?
Note that this task focuses mainly on implementing tests. You may implement also the class
Attainment (it might simplify creating the tests), but it is not necessary due to the provided
Attainment class implementations (see below).
You may use the
Attainment class implementations given in the test material subdirectory
testfiles. Theese implementations are provided in the form of readily compiled class files. The
testfiles/0 contains a working version, and the other subdirectories contain
versions that fail the JUnit tests described above.
Although you need to place your code in a Maven directory structure, you do not need to use Maven
for compiling and testing the code. The task material provides a JUnit jar-library
junit-platform-console-standalone-1.8.2.jar. If you copy it into your task root directory and
some readily provided
Attainment class file into the subdirectory
target/classes/fi/tuni/prog3/junitattainment, your JUnit tests can be compiled e.g. as
javac -cp target/classes:junit-platform-console-standalone-1.8.2.jar -d target/test-classes -sourcepath src/test/java src/test/java/fi/tuni/prog3/junitattainment/*.java.
The JUnit tests can then be run e.g. as
java -jar junit-platform-console-standalone-1.8.2.jar -cp target/classes/:target/test-classes -p fi.tuni.prog3.junitattainment.
You may switch the tested
Attainment class version by simply copying a different class file into
The automated tests are based on the same readily provided
Attainment class implementations.
You will receive full points if your JUnit tests find no errors from the implementation in
testfiles/0 but find errors from all other provided implementations.
A+ presents the exercise submission form here.