3

在我的应用程序中,我有两个用于输入用户名和密码的文本字段。我需要编写测试用例来检查密码字段是否为空。我设置了测试环境,我知道如何从测试类中调用方法,但我不知道如何编写测试用例。请帮我写一个测试用例。

4

1 回答 1

3

我将从一个看起来像这样的测试开始:

@implementation LoginViewTests

- (void)testPasswordFieldIsNotEmpty {
    LoginViewController *loginView = [[LoginViewController alloc] init];
    //any other setup such as calling -viewDidLoad
    STAssertTrue([loginView.passwordField.text length] > 0, @"The field should not be empty");
    [loginView release]; //unless you're using ARC
}

@end

现在,这是否通过了(实际上它甚至可以建立)?如果没有,请对您的代码进行必要的更改。

于 2012-02-08T15:50:24.620 回答