目录
1.背景知识
在测试过程中,我们可能会遇到这样的函数,它的参数有许多特殊值,我们需要把这些特殊值都要进行测试。比如测试“登录”函数,测试中比如需要测试用户名密码正确、用户名不正确、密码不正确。在编写测试类的时候,至少要写3个测试方法,才能把这3种情况都包含。
2.例子
被测代码:
public class Register {
public boolean LogOn(String username, String password) {
if (username == "Admin" && password == "123456") {
return true;
} else {
return false;
}
}
}
测试代码段:
import static org.junit.Assert.*;
import org.junit.Test;
public class RegisterTest {
priv