Arrange, Act, and Assert Your Way to a Test
This lesson will cover a complete walkthrough of JUnit Testing and a comprehensive breakdown of its process.
We'll cover the following
A Test Case
Let’s start with a scenario that provides an example of the expected behavior of the target code. To test a ScoreCollection
object, we can add the numbers 5
and 7
to the object and expect that the arithmeticMean
method will return 6
(because (5+7)/2 is equal to 6).
Remember that naming is important. We call this test answersArithmeticMeanOfTwoNumbers
, which nicely summarizes the scenario laid out in the test method.
Run the modified ScoreCollectionTest
below to check if it passes.
Get hands-on with 1400+ tech skills courses.