i trying to cover the test case
a method which return class object.
-(ClassName *)returnClass{
return _class;
}
-(void)test_ReturnClass{
id returnObj;
returnObj = [aClassNameObj returnClass];
STAssertNotNil(returnObj, @"return Not NULL Value");
STAssertEqualObjects(returnObj, [isKindOfClass: ClassName],@"");
}
I want to compare an show STAssertEqualObjects
isKindOfClass:ClassName
is it possible if yes please let me know.
@All Thanks In advance
It's unclear what you're asking.
If you want to check if the returned object's class is ClassName
or a subclass, you can use something like this:
STAssertTrue([returnObj isKindOfClass:[ClassName class]], nil);
If you want to check that it's a ClassName
and not a subclass (this seems permissible in a unit test, but not in normal code), instead use something like this:
STAssertTrue([returnObj isMemberOfClass:[ClassName class]], nil);
If you really want to use STAssertEqualObjects, you might use something like this (this also checks that the classes are equal; it does not allow the instance to be a subclass):
STAssertEqualObjects([returnObj class], [ClassName class], nil);
Personally, I'd stick to option 1. Option 2 is something I've never needed to use in production code, and option 3 is even worse (there are a few legitimate uses of [foo class]
, but comparing it to another class with -equals:
isn't really one of them).