When testing public constructor calls the JUnit tests in my application produce temporary objects that are never used anywhere within the test methods. The compiler subsequently complains about unused object allocation. Is there a way to suppress compiler warnings selectively for all JUnit tests? The tests are in a separate package.
I think the answer is no, not at the package level. I tend to "cheat" and define my inner objects for testing purposes as protected
. That works around the "unused"
warnings at least:
protected static class TestFoo {
...
}
As @user47900 pointed out, you can obviously use the SuppressWarnings
annotation to get around a single warning but they usually need to be defined per class and cannot cover all inner classes nor packages.
@SuppressWarnings("unused")
private static class TestFoo {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With