Testing / JUnit6 Interview Questions
What is the ConsoleLauncher and how do you run JUnit 6 tests from the command line?
The ConsoleLauncher (junit-platform-console-standalone) is a self-contained JAR that can discover and run JUnit 6 tests from the command line without Maven or Gradle. It is useful for CI scripts, Docker containers, and quick local runs.
# Download the standalone JAR: # From: https://repo1.maven.org/maven2/org/junit/platform/ # junit-platform-console-standalone/6.1.1/ # junit-platform-console-standalone-6.1.1.jar # Basic run: scan classpath for tests java -jar junit-platform-console-standalone-6.1.1.jar \ --scan-class-path \ --classpath "target/test-classes:target/classes" # Select specific class: java -jar junit-platform-console-standalone-6.1.1.jar \ --select-class "com.example.OrderServiceTest" # Select by package: java -jar junit-platform-console-standalone-6.1.1.jar \ --scan-class-path \ --select-package "com.example.unit" # Filter by tag: java -jar junit-platform-console-standalone-6.1.1.jar \ --scan-class-path \ --include-tag "fast" \ --exclude-tag "slow" # Fail fast (JUnit 6 CancellationToken): java -jar junit-platform-console-standalone-6.1.1.jar \ --scan-class-path \ --fail-fast # Generate XML report (for CI systems like Jenkins): java -jar junit-platform-console-standalone-6.1.1.jar \ --scan-class-path \ --reports-dir ./test-reports
More Related questions...