单元测试

Junit单元测试框架

使用

断言测试 使用Assert.assertEquals(message, 预期值, 实际值);
这段代码是用于在测试中验证某个方法的返回值是否符合预期。其中,"方法内部有bug"是用于在断言失败时显示的提示信息。4是预期的返回值,index2是实际的返回值。如果预期的返回值和实际的返回值不相等,断言会失败并抛出一个错误,测试会停止执行。
//断言机制,程序员可以通过预测业务方法的结果。
Assert.assertEquals("方法内部有bug", 4, index2);
可以右键单击项目,点击run->All Test 就可以测试项目中的所有测试方法
Junit单元测试框架的常用注解
