CKTIS / Java
Deterministic testing
Deterministic testing: A deterministic test arranges input, executes one behavior, and checks an observable result; a unit test isolates the contract of a small unit.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
testingA deterministic test arranges input, executes one behavior, and checks an observable result; a unit test isolates the contract of a small unit.
Check boundaries, results, and the exact expected exception type, while injecting time, randomness, and dependencies as controlled sources.
The assert statement is disabled by default without -ea, so it cannot replace input validation or always-running test assertions.
Compare floating-point values with a tolerance; concurrent tests need explicit synchronization and a timeout rather than sleep.
Two explicit checks pass and increment both counters, so the sole line tests=2 passed=2 proves every test ran without -ea.
Examples
public class Main {
private static int tests;
private static int passed;
static void check(boolean condition) {
tests++;
if (!condition) throw new AssertionError("test " + tests);
passed++;
}
public static void main(String[] args) {
check(2 + 3 == 5);
check("JAVA".toLowerCase(java.util.Locale.ROOT).equals("java"));
System.out.println("tests=" + tests + " passed=" + passed);
}
}
Result
tests=2 passed=2
Two explicit checks pass and increment both counters, so the sole line tests=2 passed=2 proves every test ran without -ea.