Skip to content

Add unit tests for Listener and fix the test runtime - #125

Merged
0verEngineer merged 2 commits into
0verEngineer:mainfrom
leoweigl:test/unit-tests
Oct 23, 2026
Merged

0verEngineer merged 2 commits into
0verEngineer:mainfrom
leoweigl:test/unit-tests

Conversation

@leoweigl

Copy link
Copy Markdown
Contributor

This adds the first unit tests to the project and fixes the test runtime so ./gradlew test works.

Test runtime fix

With the first test under src/test/java, ./gradlew test failed before running any test:
NoClassDefFoundError: org/junit/runners/model/Statement.
The IntelliJ Platform test framework refers to JUnit 4 classes even with JUnit 5
(see the IntelliJ Platform Gradle Plugin FAQ,
"JUnit5 Test Framework refers to JUnit4"). I added junit:junit:4.13.2 as testRuntimeOnly,
so it is only on the runtime classpath and cannot be used by test code.

Tests (ListenerTest)

  • IDs are unique (they are persisted in the user settings, a duplicate would silently map to the wrong listener)
  • fromId returns the matching listener for every known ID
  • fromId returns DEFAULT for unknown IDs (parameterized)

Comments I left unchanged

Two comments in build.gradle.kts are slightly outdated now, I did not want to change them without your opinion:

  • above testIdeUi: "adding the first test under src/test/java is all it takes" (the JUnit 4 dependency was needed as well)
  • above instrumentTestCode: "Pointless without test sources" (there are test sources now, the task stays disabled
    because of the InstrumentCodeTask crash; tests run fine with it disabled)

Tested locally on Windows with JDK 21 (./gradlew test, 6 tests green).

@0verEngineer

Copy link
Copy Markdown
Owner

Thanks, looks good! Please update the three outdated comments in this PR:

  1. build.gradle.kts, above testIdeUi: "adding the first test under src/test/java is all it takes" no longer holds, since the JUnit 4 runtime dependency was needed too. "runs an empty suite" is also outdated now that there are tests under src/test.
  2. build.gradle.kts, above instrumentTestCode: "Pointless without test sources" is outdated now. The task stays disabled only because of the InstrumentCodeTask crash.
  3. .github/workflows/run-ui-tests.yml, header: it has the same outdated note ("no UI tests yet … empty suite … adding the first test under src/test is enough") and should be adjusted the same way as 1.

@leoweigl

Copy link
Copy Markdown
Contributor Author

Updated all three comments, thanks!

@0verEngineer
0verEngineer merged commit 14ba181 into 0verEngineer:main Oct 23, 2026
5 checks passed
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