Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating JUnit stubs for new methods in existing class in Eclipse

Tags:

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?

like image 869
Dan Coates Avatar asked Oct 26 '10 14:10

Dan Coates


People also ask

How do you write a JUnit for an existing project?

To use JUnit you must create a separate . java file in your project that will test one of your existing classes. In the Package Explorer area on the left side of the Eclipse window, right-click the class you want to test and click New → JUnit Test Case. A dialog box will pop up to help you create your test case.

How do I update JUnit in Eclipse?

The steps are as below: Project > Properties > Java Build Path > Libraries. Click "Add External JARs..." button at right side --> Select your preferred JUnit jar. Click OK button.

How do you make test cases automatically?

To record the test case, click on the TestCase Studio icon on the toolbar. Now keep performing your steps, it will automatically record all the user actions. You can save the recorded steps by clicking on the Download Test Case button.

How do you write JUnit test cases for model classes in Java?

@RunWith(MockitoJUnitRunner. class) public class MyClassTest{ @InjectMocks MyClass myClass; @Mock MyDAO myDAO; private MyObject myObj; private List<MyObject> objList; @Before public void setUp() throws Exception { myObj = new MyObject(); myObj.


1 Answers

  1. Install the MoreUnit extension from the MarketPlace.
  2. Open the package hierarchy panel.
  3. Navigate down to the class that you've modified.
  4. Right click on the new method.
  5. Select "Generate Test". The generated stub will appear in your ClassTest file.
like image 76
Chelmite Avatar answered Oct 26 '22 01:10

Chelmite