I have a view controller called SubMenuViewController and a label in it called selectionLabel. The view controller is present in the storyboard and I am writing unit tests for testing SubMenuViewController.
I have a method:
- (void)drawerItemSelectedWithIndex:(NSInteger)selectionIndex
{
if(selectionIndex == 0)
{
self.selectionLabel.text = @"All";
}
else
{
self.selectionLabel.text = @"Test";
}
}
I want to write unit test cases for this. I have created an extension.
@interface SubMenuViewControllerTests : XCTestCase
@property(nonatomic)SubMenuViewController *subMenuViewController;
@end
@interface SubMenuViewController()
@property(nonatomic)IBOutlet UILabel *selectionLabel;
@end
And This is the test method I have written:
-(void)testCCKFNavDrawerSelectionWithIndex
{
[self.subMenuViewController drawerItemSelectedWithIndex:0];
XCTAssert([self.subMenuViewController.selectionLabel.text isEqualToString:@"All" ]);
}
Is this the right way to test this method, as I am getting value of self.subMenuViewController.selectionLabel as nil.
Aucun commentaire:
Enregistrer un commentaire