Skip to content

feat(junit5): add JUnit5 reporter#160

Merged
nizos merged 4 commits into
nizos:mainfrom
Hiro-Chiba:feat/junit5-reporter-core
Apr 18, 2026
Merged

feat(junit5): add JUnit5 reporter#160
nizos merged 4 commits into
nizos:mainfrom
Hiro-Chiba:feat/junit5-reporter-core

Conversation

@Hiro-Chiba

@Hiro-Chiba Hiro-Chiba commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces a JUnit5 reporter at reporters/junit5/ following the canonical test.json schema. Draft opened after initial scaffolding to confirm direction before implementing the listener logic.

Questions for @nizos

  1. Maven group ID: I used io.github.nizos as a placeholder. Preference?
  2. Minimum JDK: 17 or 11?
  3. Kotlin: cover via JUnit5, or separate tdd-guard-kotest later?
  4. Build tool: Gradle only, or Maven too?

Refs #67, #80.

@nizos

nizos commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Great start @Hiro-Chiba,

  1. io.github.nizos works great!
  2. Let's go with 17.
  3. Agreed, JUnit5 covers the common cases. kotest reporter can be its own thing later.
  4. Gradle is fine for building the reporter itself. We can document the installation for both.

@Hiro-Chiba

Hiro-Chiba commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

Pushed the listener, collector, JSON writer, SPI registration, and the Gradle wrapper. All 28 unit tests pass locally on JDK 17.

Planning to continue in separate PRs to keep each focused on a single concern:

  1. reason field (passed/failed/interrupted)
  2. stack field on test errors
  3. unhandledErrors for BeforeAll / AfterAll hook failures
  4. Compilation failure handling (synthetic failed module, Go/Rust style)

Happy to adjust order or scope based on your preferences. Ready for review.

@Hiro-Chiba Hiro-Chiba marked this pull request as ready for review April 15, 2026 18:41
@nizos nizos force-pushed the feat/junit5-reporter-core branch from a8ed7ec to db69084 Compare April 18, 2026 09:01
Sets up the JUnit5 reporter directory following the minitest/rspec
reporter conventions:

- Gradle Kotlin DSL build with Java 17 toolchain and Maven publishing
- Canonical schema model classes (TestResult, TestModule, TestCase, TestError)
  matching src/contracts/schemas/reporterSchemas.ts
- ProjectRootResolver per ADR-009 (accepts absolute and relative paths)
  and ADR-010 (explicit > TDD_GUARD_PROJECT_ROOT > error; no silent cwd fallback)
- README skeleton

Tests not yet run locally pending Java 17 environment setup.
ProjectRootResolverTest covers 8 cases: missing config, explicit path
precedence, env var fallback, absolute and relative path handling, and
cwd-within-root validation.

Refs nizos#67, nizos#80. Design inspired by @jsbattig's listener architecture.
Implements the result capture pipeline for the JUnit5 reporter:

- TddGuardListener registers via META-INF/services and writes results on
  test plan completion. Activates only when TDD_GUARD_PROJECT_ROOT is
  set so the jar is safe to include on a classpath without opting in.
- TestResultCollector groups outcomes by moduleId (fully qualified class
  name). Pure data layer with no JUnit Platform dependency so it is
  directly unit-testable.
- TestJsonWriter serializes to the canonical schema defined in
  src/contracts/schemas/reporterSchemas.ts with atomic temp-file write.
  No external JSON library dependency.

Tests: 11 cases for TestJsonWriter (passed/failed/skipped, escaping,
atomic write, nested directory creation) and 9 for TestResultCollector
(grouping, state extraction, throwable handling, insertion order).

Tests not yet run locally pending Java 17 environment setup.

Refs nizos#67, nizos#80.
Generated via `gradle wrapper --gradle-version 8.10`. Lets reviewers and
CI run `./gradlew test` without installing Gradle globally.

Verified on JDK 17.0.18 (Homebrew): all 28 unit tests pass
(ProjectRootResolver 8, TestJsonWriter 11, TestResultCollector 9).
@nizos nizos force-pushed the feat/junit5-reporter-core branch from db69084 to 70e33cd Compare April 18, 2026 10:20
@nizos

nizos commented Apr 18, 2026

Copy link
Copy Markdown
Owner

Hi @Hiro-Chiba,

Looking good! I noticed a gap in testing for TddGuardListener, did the test file slip through? Let's address this before merging.

We can also look into adding the test factory and integration tests in follow-up PRs.

I rebased the branch to pick up the new fixes on main so your checks don't fail. On a side note, I started a new project that I would like to discuss with you if you're interested. Reach me by email, you'll find it in the commit details. :)

Injects envAccessor into TddGuardListener so the activation check
is testable without depending on System.getenv. The public SPI
constructor still delegates to System::getenv.

Seven test cases covering:
- no-op when env var is unset or empty
- test.json written when configured
- passed, failed (with error message), and skipped capture
- container events ignored (only test-level events recorded)
- graceful disable when project root is invalid

Addresses review feedback from @nizos on nizos#160.
@Hiro-Chiba

Copy link
Copy Markdown
Contributor Author

Thanks @nizos! Added TddGuardListenerTest with 7 unit tests covering activation, result capture, and graceful disable. Also refactored the listener to inject the env accessor for testability.

Planning to add the test factory and integration tests in follow-up PRs.

I sent you an email, looking forward to hearing about the project!

@nizos nizos merged commit 132f8b5 into nizos:main Apr 18, 2026
11 checks passed
@Hiro-Chiba Hiro-Chiba deleted the feat/junit5-reporter-core branch May 10, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants