spf4j
spf4j copied to clipboard
slf4j-test feature: warn if an expectation is created but never asserted on
With this sort of case
LogAssert expect = TestLoggers.sys().expect("org.spf4j.test", Level.WARN,
LogMatchers.hasFormat("Booo"));
LOG.warn("Booo", new RuntimeException());
// oops, lost the `assertObservation`!
the test will not fail if it does not produce the expected logs.
The @ExpectLog
annotation avoids this hazard, but it is limited by the annotation requirement of only using compile-time values.
It'd be nice to have ways that make sure the assertion always runs and that still let you use matchers.
(Exactly how that looks probably depends on the test framework.)
A static analysis tool like findbugs and spotbugs should highlight this.
(LogAssert uses: edu.umd.cs.findbugs.annotations.CleanupObligation; edu.umd.cs.findbugs.annotations.DischargesObligation)
however what you are suggesting is doable... let me think about it.