I want to write unit tests using Apple’s default SenTestingKit for the below method:
- (NSDictionary*)getValueTags {
return _tags;
}
- (NSString*)getFlag {
NSString* jo = @"";
for (NSString* key in _tags) {
jo = [jo stringByAppendingFormat:@"%@=\"%@\"&", key, [_tags objectForKey:key]];
}
if ([jo length] > 0) {
jo = [jo substringToIndex:[jo length] - 1];
}
return jo;
}
I used default SenTesting
- (void)setUp
{
[super setUp];
// Set-up code here.
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
-(void)testValueTags{
}
-(void)testGetFlag{
}
I am new to writing TestCases, I need some guideline for sample methods to write test cases
A test case has four distinct phases:
Some of these phases can be empty. For example, most tear down happens automatically if you use ARC.
When you’re starting, don’t put anything into the
setUportearDownmethods. Just write a single unit test. Here’s a worked example. (I’m going to change the names, because Objective-C idiom is not to use the word “get”. So instead ofgetFlaglet’s just call itflag.) I’m going to call the class `Example, and I’ll use ARC. And I use the abbreviation “sut” for “system under test”.That’s one test. Let’s add another.
At this point, we have duplicate code: the creation of the sut. Now we can promote the variable up to an instance variable of the class. Then we create it in
setUpand destroy it intearDown:For a more involved example, see Objective-C TDD: How to Get Started.