我想对此方法进行功能单元测试,作为Junit4测试的示例
QISP.id
QISeventlog.id
QISprocess.id
gl.nm
QISbatchlog.nm
QISprocess.nml
QISvariable.nml
答案 0 :(得分:0)
假设您已经阅读了how to create local Unit Tests in Android Studio,因为您只测试String
的有效长度,您需要检查以下情况:
null
字符串所以这样的事就足够了(假设你的班级被称为PasswordChecker
,用其实际调用的东西替换):
private PasswordChecker checker;
@Before public void setUp() {
checker = new PasswordChecker();
}
@Test public void testValidPassword() {
assertTrue(checker.validatePasswordExpression("validPassword1"));
}
@Test public void testShortPasswordReturnsFalse() {
assertFalse(checker.validatePasswordExpression("Short"));
}
@Test public void testNullPasswordReturnsFalse() {
assertFalse(checker.validatePasswordExpression(null));
}
@Test public void testLongPasswordReturnsFalse() {
assertFalse(checker.validatePasswordExpression("ThisPasswordIsWayTooLongSoTrySomethingElse"));
}
@Test public void testEightCharPasswordReturnsTrue() {
assertTrue(checker.validatePasswordExpression("IsValid1"));
}
@Test public void testNinteenCharPasswordReturnsTrue() {
assertTrue(checker.validatePasswordExpression("ThisPasswordIsValid"));
}
@Test public void testTwentyCharPasswordReturnsFalse() {
assertFalse(checker.validatePasswordExpression("ThisPasswordIsTwenty"));
}