This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Create JUnit Tests action generates unit test also for interfaces. That: * does not make any sense; and * generate code is not compilable (extends is used instead of implements)
> Create JUnit Tests action generates unit test also for interfaces. That: > * does not make any sense; and It is not true. There are cases when it is needed, e.g. see an example here: http://en.wikipedia.org/wiki/Unit_testing#Design FYI A stub implementation of your interface will be automatically generated for you in the test class as a nested class. You could consider a final version of that implementation as a reference implementation, and use it as a proof of concept for your interface. > * generate code is not compilable (extends is used instead of implements) I agree it is a bug.
OK, "does not make any sense" is too strong statement. In practice, stub implementations of interfaces are often needed but because they are usually used from more that one test you would place them as top level classes. My usecase for filling this issue was: I generated an EJB with Local and Remote interfaces (a class + 2 interfaces in a package). I did it twice and then I wanted to generate unit tests for my two EJBs so I right clicked package and used Generate JUnit Tests action which resulted in 4 stub implementations/tests which do not make any sense. In most of the cases I would use Generate JUnit Test action on single files so this part of the problem is certainly not high priority one. Thanks for fixing incorrectly generated code.
David, To fix this issue I'll correct the test code generating in a part of generating a nested class implementing an abstraction under test, so that: - "implements" will be used for both interfaces and annotation types - "extends" will be used for both classes and enums. Could you please, check such approach from viewpoint of existing EJB functionality.
That sounds good. Perhaps "Create Tests" customizer (when executed on a package) should in addition to "Abstract Classes" option has also "Interfaces/Annotations" option? That would give user control. Or will you use "Abstract Classes" one for interfaces as well and do not generate stubs for interfaces if the option is set to false?
I'm absolutely agree with you, we need have additional options in the "Create Tests" dialog, but it seems it is a separate P3 enhancement for the next release/update.
Fixed in the main trunk: http://hg.netbeans.org/main/rev/32d829516966
See also Enhancement Issue 173120 - Processing of units should be improved
Thanks.
Integrated into 'main-golden', will be available in build *200909270201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/32d829516966 User: Victor G. Vasilyev <vvg@netbeans.org> Log: Issue #172723 - Incorrect code of the unit test generated for interfaces
*** Bug 169565 has been marked as a duplicate of this bug. ***