Java Core
    Java - Overview
    What is new in Java 21
    What is new in Java 17
    What is new in Java 11
    Java - JVM
    Java - Deprecated
    Java - Numbers
    Java - String
    Java - Time
    Java - Collections
    Java - Lambda
    Java - Exceptions
    Java - Switch
    Java - IO
    Java - Jar
    Java - Generics
    Java - Environment
    Java - Concurrency
    Java - Trouble Shooting
    Java - Install
    Java - Misc

JUnit

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>);