rakeshNS
rakeshNS

Reputation: 4257

How to write a test case?

In my application, I have two text fields for entering User-name and Password. I need to write test case for checking Password field is not empty. I Set Up the testing environment and I know how to call methods from testing class, but I don't know how to write test case. Please help me to write a test case.

Upvotes: 3

Views: 1450

Answers (1)

user23743
user23743

Reputation:

I'd start with a test that looks something like this:

@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

Now, does that pass (indeed does it even build)? If not, make the necessary changes to your code.

Upvotes: 3

Related Questions