spf4j icon indicating copy to clipboard operation
spf4j copied to clipboard

slf4j-test feature: warn if an expectation is created but never asserted on

Open keturn opened this issue 4 years ago • 1 comments

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.)

keturn avatar May 01 '20 02:05 keturn

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.

zolyfarkas avatar Jun 02 '20 20:06 zolyfarkas