1)选中当前工程 - 右键选择build path - add libraries - JUnit 4 - finish
2)创建java类,进行单元测试
此时的java类要求:
此类为public;此类提供公共的无参构造器;
3)在此类中声明单元测试方法
要求:
此方法的权限是public;没有返回值;没有形参;
4) 此单元测试方法上需声明注解@Test,并导入import org.junit.Test;
5)声明好单元测试方法后,就可以在方法体内测试相关的代码
6)写完代码后,左键双击单元测试方法名,右键 - run as - JUnit Test
import org.junit.Test;
public class JUnitTest {
int num = 10;
@Test
public void testEquals() {
String s1 = "MM";
String s2 = "MM";
System.out.println(s1.equals(s2));
System.out.println(num);
}
}