Suppress compiler warnings in JUnit tests

When testing a public constructor call, the JUnit tests in my application create temporary objects that are never used anywhere within the test methods. The compiler then complains about the placement of unused objects. Is there a way to suppress compiler warnings selectively for all JUnit tests? Tests are in separate packaging.

+4
source share
1 answer

I think the answer is no, not at the package level. I tend to cheat and define my internal objects for testing purposes as protected . This works with at least "unused" warnings:

 protected static class TestFoo { ... } 

As @ user47900 noted, you can use the SuppressWarnings annotation to get around a single warning, but they usually need to be defined for each class and cannot cover all inner classes and packages.

 @SuppressWarnings("unused") private static class TestFoo { ... } 
+5
source

Source: https://habr.com/ru/post/1392794/


All Articles