Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress Compiler Warnings in JUnit Tests

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.

like image 836
Petr Avatar asked Jan 24 '12 21:01

Petr


1 Answers

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 {
   ...
}
like image 59
Gray Avatar answered Oct 21 '22 15:10

Gray