JUnit
Last Updated: 2021-11-19
Import @Test
import org.junit.Test;
Import Assertion(assertEquals, etc)
import static org.junit.Assert.*;
Key Conceptions
- Assert: throws exceptions if fail.
- Test: a method annotated with @Test
- Test Class / TestCase: a class contains test methods annotated with @Test
- Test Suite: a group of tests.
- Test Runner: runs test suites.
Methods
optional <message>
provide the human-readable error information.
optional <delta>
provide an error range.
assertEquals
assertEquals([<message>,] <expected>, <actual> [, <delta>]);
assertArrayEquals
assertArrayEquals([<message>,] <expected>, <actual>);
assertSame
assertSame([<message>,] <expected>, <actual>);
assertTure
assertTrue([<message>,] <expression>);
assertNotNull
assertNotNull([<message>,] <expression>);