tags:

views:

20

answers:

1

This question is tangentially related to How can I create JUnit stub methods in eclipse? but it doesn't answer my specific question.

Assuming you have an existing JUnit test case class, if you add a method to the target class (or choose to test a previously untested method), is there a way to tell Eclipse to generate the stub for the "new" method(s) in the existing TestCase without creating a new test case class?

A: 

The usual working cycle with unit tests is to create the test case first

public void test_new_method() {
    ClassUnderTest x = new ClassUnderTest();
    x.NewMethod();
}

At that point Eclipse will give you a warning that the method "NewMethod" does not exist. Than you simply select a "Quick Fix" (Ctrl-1 or Ctrl-2 i'm not sure) to create the missing method in the class.

khmarbaise
Good point, but that doesn't answer my initial question. Eclipse generates the stubs for new test case classes, why can't it generate method stubs for existing classes?
Dan Coates
Sorry for not answering the question but the in Eclipse they (whoever) assume you're working test driven...so test first and then the code...I just checked the help of Eclipse and couldn't find a possibility to do it the way you like it...sorry.
khmarbaise