The four methods in CalculateTest in the previous article are all hand-tapped. It would be better if there were fewer methods, but when would there be more? Let's talk about a method of semi-automatically generating Test method .
Select Calculate.java in the left view of MyEclipse---->Right click---->New---->Other....---->JUnit Test Case---->Next, then A picture like the following will pop up:
There are two places that need to be changed:
1. Source Folder: The default is src, change it to test, because this Test Case, it is better to put it in the test resource package
2. Name: Give this Test Case a name
The other defaults are enough, Next, the following box will pop up:
Check the method you want it to generate Test for you, I have selected all here, and then Finish. The final generated code is as follows:
package com.wjl.junit; import static org.junit.Assert.*; import org.junit.Test; public class CalculateTestByAuto { @Test public void testAdd() { fail("Not yet implemented"); } @Test public void testSubtract() { fail("Not yet implemented"); } @Test public void testMultiply() { fail("Not yet implemented"); } @Test public void testDivide() { fail("Not yet implemented"); } }
Is it convenient? ?
Finally, thank you teacher for sharing, and wish everyone good luck!