Skip to content

Run Issue792 and DateTimeFormatTest.bothPathsRejectSpaceSeparator tests - #1371

Merged
stevehu merged 4 commits into
networknt:masterfrom
sharanggupta:run-never-run-tests
Oct 28, 2026
Merged

stevehu merged 4 commits into
networknt:masterfrom
sharanggupta:run-never-run-tests

Conversation

@sharanggupta

Copy link
Copy Markdown
Contributor

Issue792 (the fail-fast pattern test from #795) has never run because its name doesn't match Surefire's default test class patterns, and DateTimeFormatTest.bothPathsRejectSpaceSeparator from #1331 has no @test. This renames the class to Issue792Test and adds the annotation; both pass.

Issue792 did not match the Surefire test class name patterns and
bothPathsRejectSpaceSeparator had no @test annotation, so neither ran.
@stevehu

stevehu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Reviewed this and ran both affected classes on the PR branch. Issue792Test (1 test) and DateTimeFormatTest (120 tests, including bothPathsRejectSpaceSeparator) pass. I found nothing blocking, only three minor test-quality points:

  1. Issue792Test can't tell fail-fast on from off. The schema has a single violation, so validate(...) returns 1 error with failFast(true) and with failFast(false). It only catches the original PatternValidator does not pass exception to client #792 regression where the pattern validator swallowed the fail-fast exception. A second failing property, asserting 1 error under fail-fast and 2 without it, would exercise the feature the test is named for.
  2. bothPathsRejectSpaceSeparator duplicates existing coverage. rejectsNonTSeparators already includes "2020-01-01 12:00:00Z" and asserts it is rejected through the schema (the Ethlo path) and by JavaTimeOffsetDateTime. validatesWithTheJavaTimeFallbackWhenEthloIsAbsent asserts the same value without Ethlo. The only thing the new test adds is a direct Ethlo.isValid call, which could be folded into rejectsNonTSeparators instead of kept as a one-value test.
  3. Nothing prevents this recurring. Surefire's default name patterns plus JUnit 5 skipping methods that lack @Test let both cases go unnoticed. A small meta-test could scan test sources for classes with @Test that don't match the Surefire patterns (excluding *IT) and for void methods missing the annotation. An explicit Surefire <includes> list would cover the class-name half.

I also scanned src/test/java for other silently skipped tests. The only other hit was InternalPackageIT, which runs in verify on purpose.

Validate two violating properties: one error with fail-fast, two without. Fold the direct Ethlo check from bothPathsRejectSpaceSeparator into rejectsNonTSeparators, which already covers that value.
TestDiscoveryTest scans src/test/java for test classes whose names the Surefire includes (or *IT) don't match, and for no-argument void methods that have no annotation and are not called from their file.
@sharanggupta

Copy link
Copy Markdown
Contributor Author

Done: 2210a3c makes Issue792Test validate two violating properties (1 error with fail-fast, 2 without) and folds the Ethlo check into rejectsNonTSeparators, and 3270fce adds TestDiscoveryTest, which fails on a misnamed test class or an unannotated test method.

@stevehu

stevehu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Re-reviewed the updated branch (3270fce). The three earlier points are addressed: Issue792Test now asserts 1 error with fail-fast and 2 without, the duplicate space-separator test is folded into rejectsNonTSeparators, and TestDiscoveryTest adds a guard. Issue792Test, DateTimeFormatTest and TestDiscoveryTest all pass.

I tried the new guard against some sample bad inputs. It flags a plain unannotated method with a unique name, but it misses these:

  1. Any *IT class slips through. The class-name regex ends in \w*IT, but only InternalPackageIT is run (by name, in verify). A FooIT with a @Test method passed the guard and would never run. Narrowing it to InternalPackageIT would close this.
  2. isCalled hides unannotated methods. A method is exempted if its name appears anywhere else in the file. void test() is always exempted because the word "test" shows up in comments, and void hiddenCase() was exempted by a // mirrors hiddenCase comment.
  3. isAnnotated is too lenient. A previous line ending in ) (for example // see issue (1331)) or any annotation (for example @SuppressWarnings) counts as annotated, so the method is not flagged.
  4. TEST_ANNOTATION misses fully-qualified annotations. A misnamed class that uses only @org.junit.jupiter.api.Test isn't detected. In the other direction, @Test text in a comment or string would be flagged as a misnamed class.
  5. Minor: the source path is working-directory relative. Paths.get("src","test","java") works under Surefire but fails with NoSuchFileException if the class is run from another working directory.
  6. Minor: repeated file reads. Each test source is read several times, and a new Pattern is compiled per method. The cost is small today.

Item 1 is the one worth fixing before merge; the rest are heuristic limits you may prefer to accept and document.

Only InternalPackageIT is exempt by name. Comments and literals are blanked before matching. A method counts as annotated only with a JUnit annotation, and as a helper only if it is called. Qualified annotations are matched. The source root comes from the test classes location, and each file is read once. Methods of nested and anonymous classes are not test candidates.
@sharanggupta

Copy link
Copy Markdown
Contributor Author

Done in c997990, all six: only InternalPackageIT is exempt by name, comments and literals are blanked before matching, a method counts as annotated only with a JUnit annotation and as a helper only if it is actually called, qualified annotations are matched, the source root comes from the test classes location, and each file is read once. Checked against your examples plus a FooIT, a qualified-only class and a comment-only @Test; methods of anonymous classes such as Runnable.run() are not candidates.

@stevehu

stevehu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Reviewed the latest commit (c997990, "Tighten TestDiscoveryTest"). It closes the gaps I raised last time. I re-ran my sample bad inputs against it:

  • a FooIT class with @Test is now caught;
  • a class using only @org.junit.jupiter.api.Test is now caught;
  • an unannotated test() with a nearby comment ending in ) and only @SuppressWarnings is now caught;
  • the working-directory dependency is gone.

TestDiscoveryTest, Issue792Test and DateTimeFormatTest all pass. Remaining points, all minor:

  1. @Override methods are flagged. A test class with @Override public void run() {} (I used implements Runnable) fails testShapedMethodsHaveATestAnnotation, because @Override isn't in JUNIT_METHOD_ANNOTATION and the name isn't called elsewhere. Exempting @Override would fix it.
  2. A same-name call or overload still hides a skipped test. An unannotated void size() {} passed because the file also calls List.size(), and an unannotated void hiddenCase() passed because an overload int hiddenCase(int) exists. callCounts counts any name( token.
  3. @Nested classes aren't checked. braceDepth == 1 skips them, so @Nested class Inner { @Test void a() {} void missed() {} } passes. The Javadoc says nested classes are out of scope, which suits anonymous classes but not @Nested containers.
  4. RUN_BY_NAME duplicates the pom. It must match <test>InternalPackageIT</test> by hand, and only a comment links them.
  5. testSourceRoot assumes <root>/target/test-classes. An IDE output directory such as out/ or bin/, or a Maven <directory> override, makes it resolve the wrong path and fail with NoSuchFileException. Surefire sets the basedir system property, which could be used first.

None of these block the PR. Items 1 and 2 are the most likely to cause trouble, and a future false positive in item 1 would push authors to work around the guard.

@stevehu
stevehu merged commit 53a6c00 into networknt:master Oct 28, 2026
stevehu added a commit that referenced this pull request Oct 28, 2026
…ts (2.x) (#1372)

Backport of #1371 to 2.x.

Issue792 (the fail-fast pattern test from #795) never ran because its name
does not match Surefire's default test class patterns, and
DateTimeFormatTest.bothPathsRejectSpaceSeparator had no @test.

- Rename Issue792 to Issue792Test, and give it two failing properties so it
  tells fail-fast (1 error) from no fail-fast (2 errors).
- Fold the Ethlo assertion of bothPathsRejectSpaceSeparator into
  rejectsNonTSeparators and drop the duplicate method.
- Add TestDiscoveryTest, which fails when a test class does not match the
  Surefire includes (except InternalPackageIT, which the pom runs by name) or
  when a test-shaped method has no JUnit annotation. Ported to Java 8, which
  is the test source level on 2.x.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
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