Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Kotlin
Stage 5: Specialization

Part 11 / Topic 7 of 9

Running the tests without Gradle — verified, step by step

This is the part that was actually run, start to finish, on this machine. Gradle normally does four things: resolve dependencies, compile main, compile test, run the tests. Here, each step is done by hand with kotlinc, javac-style separate output directories, and the JUnit Platform Console launcher — the same console runner Gradle's test task drives internally.

Step 0 — get the three jars Gradle would otherwise fetch. These are the exact artifacts and versions from section 3's dependencies { } block, downloaded once by hand into a local lib/ folder (not committed — like all build output in this repo, it's .gitignored):

$ mkdir lib
$ curl -sS -o lib/junit-platform-console-standalone-1.14.5.jar \
    https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/1.14.5/junit-platform-console-standalone-1.14.5.jar
$ curl -sS -o lib/kotlin-test-2.3.21.jar \
    https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-test/2.3.21/kotlin-test-2.3.21.jar
$ curl -sS -o lib/kotlin-test-junit5-2.3.21.jar \
    https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-test-junit5/2.3.21/kotlin-test-junit5-2.3.21.jar

The console standalone jar is a single all-in-one artifact that bundles the JUnit Platform launcher plus the JUnit Jupiter (JUnit 5) and parameterized-test engines — one jar instead of six, which is why it's the practical choice for running tests without a build tool.

Step 1 — compile src/main/kotlin into its own output directory:

$ kotlinc src/main/kotlin -d build/classes/main

No errors, no output — a clean compile prints nothing.

Step 2 — compile src/test/kotlin into a different output directory, with build/classes/main and the three jars on the classpath:

$ kotlinc -cp "build/classes/main:lib/junit-platform-console-standalone-1.14.5.jar:lib/kotlin-test-2.3.21.jar:lib/kotlin-test-junit5-2.3.21.jar" \
    src/test/kotlin -d build/classes/test

Section 8 explains exactly why build/classes/test has to be a different directory from build/classes/main, with a real failure to prove it.

Step 3 — run every test under the JUnit Platform Console launcher, classpath pointing at both class directories, the two kotlin-test jars, and kotlin-stdlib.jar (needed at runtime, not just compile time — kotlinc doesn't bundle it onto the classpath for you the way -include-runtime does when building a jar). On a Homebrew install, kotlinc on PATH is a symlink into Cellar/kotlin/<version>/bin/, so realpath (not plain dirname/which) is what's needed to land on the real libexec/lib/kotlin-stdlib.jar next to it:

$ java -jar lib/junit-platform-console-standalone-1.14.5.jar execute \
    --classpath "build/classes/main:build/classes/test:lib/kotlin-test-2.3.21.jar:lib/kotlin-test-junit5-2.3.21.jar:$(dirname $(realpath $(which kotlinc)))/../libexec/lib/kotlin-stdlib.jar" \
    --scan-classpath --details=tree

Real, pasted output:

╷
├─ JUnit Platform Suite ✔
├─ JUnit Jupiter ✔
│  ├─ DiscountCalculatorParamTest ✔
│  │  └─ membership tiers map to the right percent(String, double) ✔
│  │     ├─ regular tier -> 0.0% off ✔
│  │     ├─ silver tier -> 10.0% off ✔
│  │     └─ gold tier -> 15.0% off ✔
│  └─ DiscountCalculatorTest ✔
│     ├─ unknown membership tier throws() ✔
│     ├─ final bill never exceeds the original subtotal when GST is off() ✔
│     ├─ coupon above 100 percent is clamped, never a negative total() ✔
│     ├─ gold member gets 15 percent off before GST() ✔
│     ├─ regular member with a coupon stacks correctly() ✔
│     ├─ negative subtotal is rejected() ✔
│     └─ GST is applied after all discounts, not before() ✔
└─ JUnit Vintage ✔

Test run finished after 52 ms
[        10 tests found           ]
[         0 tests skipped         ]
[        10 tests successful      ]
[         0 tests failed          ]

All ten tests (seven from DiscountCalculatorTest, three CSV rows from DiscountCalculatorParamTest) passed. This is the real transcript — nothing above was hand-written and nothing was invented; --scan-classpath is the console launcher's way of saying "find every test on the classpath yourself," which is exactly what gradle test would otherwise do for you via Gradle's own test-discovery logic.

To run just one class (useful while you're working on a single test), swap --scan-classpath for --select-class com.stepshala.billing.DiscountCalculatorTest.

Done here? The practice set for Part 11 — including the solutions — is on the part page.

Search the guide