|
JUnit v4
An Introduction |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
import statements@Test)assert___() methodsassert___() Methods
Assert.assertEquals([description,] expected, actual)
Assert.assertEquals([description,] expected, actual, tolerance)
Assert.assertEqualsArray([description,] expected, actual[, tolerance])
Assert.assertTrue([description,] actual)
Assert.assertFalse([description,] actual)
Assert.assertNull([description,] actual)
Atom
public int getAtomicNumber()
public boolean equals(Atom other)
expected element
of the @Test annotation
Atom constructorIllegalArgumentException
if either of the parameters are negativeassert___() invokations
after the exception will be thrown
@Before annotation to indicate that
the method should be invoked before every test method
and the @After annotation to indicate that
the method should be invoked after every test method
org.junit.Before
and/or org.junit.After
@Before or
@After will be invoked
before/after every test method
assert___() methods are often called
assertions, but they should not be confused with
assert statements in Javaassert___() method
can be thought of as an individual test
.jar
files in the CLASSPATH and execute a
"test runner" (commonly org.junit.runner.JUnitCore)
passing it the name of the test class