Netbeans generates an "Unused Element" hint in the sidebar and a wavy underline in the editor if I define a variable or method that goes unused. This is a very useful feature, but in the case of JUnit5 it has an unwanted effect. For example:

@Test
void myTest() { ... }

This method is recognized as an "Unused Element", although it's a Unit Test that will be called by the framework. I can add the "public" modifier to the method and the hint disappears, but then Sonar (and probably other static code analysis tools) flag this as non-compliant code. The reason is that in JUnit5 it is recommended to keep Unit Test methods package-private:

https://junit.org/junit5/docs/current/user-guide/#writing-tests-classes-and-methods

As far as I can see they give no compelling reason for that recommendation, but is there a compelling reason for Netbeans to flag package-private test methods as unused?

cheers,

Ulrich

--
iSYS Software GmbH

Ulrich Mayring | Full Stack Developer
Technology Lab / R&D

Tel: +49 (0) 89 46 23 28-0 | Fax  +49 (0) 89 46 23 28-14
email: ulrich.mayr...@isys.de

Grillparzerstraße 10 | D-81675 München
www.isys.de

Sitz der Gesellschaft: München | HRB 111760
Geschäftsführer: Stefan Fischer und Max Haller

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to