CS 458 - Week 9 Lab - 2016-10-19
A little intro to JUnit and a little demo of attempted
TDD (Test-Driven Development)
We have some dice-related user stories:
* A game player can create a game die with a specified
number of sides.
* A game player can roll a game die and see the result.
* A game player can see the current top of a game die
(the result of the latest roll)
* A game player can keep track of how many times
a game die has been rolled.
* A game player can ask how many sides a game die
has.
* In JUnit 4.4, 3 packages should be imported
in a JUnit testing class:
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
* The @Test annotation signals that the method
following is a JUnit unit test.
EACH @Test method should test the functional
correctness of ONE method in the corresponding
Java class.
traditional naming scheme: the word test followed
by the name of the method being tested
(but camelcase)
* what kinds of tests are available?
assert
assertEquals
assertFalse
assertNotNull
assertNotSame
assertNull
assertTrue
fail
...and more
FOR EXAMPLE,
assertEquals expects an optional String first
argument, describing the test,
then what its value SHOULD be (expected value)
then the call being tested;
it is PASSED if the call's result and the expected
value are EQUAL
assertTrue expects an optional String first
argument, describing the test
then a boolean condition that SHOULD be
true;
it is PASSED if that condition is true