Background: I have a project that uses Javax @Nonnull annotations. IntelliJ has a nice feature that enables / disables runtime checking of these types of annotations. However, when jUnit is run via Ant, these annotations checks are not performed. We recently discovered several unit tests that were behaving incorrectly due to this runtime checking discrepancy.
There are two quasi-solutions we are aware of but would like to avoid:
- Changing the annotation framework to either Lombok or Checker (cons: extensive changes, runtime checking performed in prod code as well as unit test code) See related for this: JUnit not null test, https://checkerframework.org/manual/#nullness-example
- Add a javax validation factor to each test (cons: easy for new tests to be non-complaint, appears to require a dependency on hibernate for the validation class that we don't want to add) See related for this: How to add run-time processing of @NotNull annotation
My Question: Is there a way to enable Javax annotation validation when running jUnit from Ant (without either changing the annotation framework or adding validators to test classes)?