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.
My problem is that I have created a Src class file with just the class decleration. I then wanted to create a JUnit test class for this src class, I right clicked on the class in the Project Window, then selected Tools -> Create JUnit test. Selected what I wanted from the dialog and selected create. I then got presented with an error message saying 'No Methods defined. Can not create Test methods'. This then refused to create a blank test class with the template. I have asked this question on the Mailing List and Marián Petráš has replied witht the following comment: 'I just looked to the bug database and found that that the bug I was talking was bug #129034 (http://www.netbeans.org/issues/show_bug.cgi?id=129034). But it was about the Create Tests dialog. The problem you are facing is slightly different in that it is the routine for creation the test class what prevents from creating an empty test class.' It seems that if there are no methods in the src class file then no empty test class will be created.
Yep, seems that creation of empty unit test class should be allowed.
I agree that generating tests for just created new class (without any methods) will be useful for a user practicing the test driven development. As far as I understood, generating tests for a class without methods was disabled because a generated class for a test case will provokes an error like this: Testcase: initializationError(javaapplication5.NewClassTest): Caused an ERROR No runnable methods java.lang.Exception: No runnable methods at java.lang.reflect.Constructor.newInstance(Constructor.java:513) To avoid such error I'll add generating a stub test method like this: @Test public void testSomeMethod() { // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } A user may use the stub test method as a start point of the test driven development.
A small stub like that would be good. Is it possible to have the template similar to if you create the JUnit test class. As in the @Test and example is commented out. so the stub would like //@Test /*public void demoMethod() { example code */
Fixed in the main trunk: http://hg.netbeans.org/main/rev/08e4224c53dd
dbeer, Commented out pieces of the code can be used only after "manual" review of the code. Otherwise, if the test method is actually implemented then a user has a chance to find generated stub method via IDE facilities, e.g. after first start of the test, via the Navigator, and so on. Note, you may disable generating of the method body in a usual way, i.e. by unselecting the check box "Code Generation / Generated Code / Default Method Bodies" in the dialog "Crete Tests" that is displayed via the menu item "Tools / Create JUnit Tests". In this case, you will have the following code: @Test public void testSomeMethod() { } A next user action is the renaming, i.e. the user will select the method name and press Ctrl+R. And... Enjoy by the test driven development!