Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
keturn opened this issue May 1, 2020 · 1 comment

Comments

@keturn
Copy link

keturn commented May 1, 2020

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

@zolyfarkas
Copy link
Owner

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.

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

No branches or pull requests

2 participants