- 软件测试:黑盒测试、白盒测试
- 单元测试属于白盒测试
- 使用 Junit 进行单元测试:导包,生成测试类,run as junit
JUnit 3
- 执行顺序:setUp() -> testXxx() -> tearDown()
JUnit 4
- @BeforeClass、@AfterClass 标注的方法需要使用 修饰
- 执行顺序:@BeforeClass ->(@Before -> @Test -> @After 多个测试方法)—> @AfterClass
// JUnit 4
public class EmployeeDAOTest {
}
@After
public void destory() throws Exception {
// 测试单元,public 修饰、无返回、无参数、@Test 标注的方法
@Test
public void testXxx() throws Exception {
}
断言
- @Test 注解@Test(expected = ArithmeticException.class):期望该方法出现 ArithmeticException 异常@Test(timeout = 400):期望该方法在 400 毫秒之内执行完成