【发布时间】:2015-01-15 00:58:19
【问题描述】:
我是目标 c 的学习者,并且开始进行单元测试,
我想在对象下面进行单元测试
@interface Media : NSObject{
}
@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly) NSString *sex;
@property (nonatomic, readonly) NSString *Description;
- (instancetype)initWithDictionary:(NSDictionary *)mediaData;
@end
#import "Media.h"
@interface Media()
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *sex;
@property (nonatomic, strong) NSString *Description;
@end
@implementation Media
- (instancetype)initWithDictionary:(NSDictionary *)mediaData
{
self = [super init];
if (self)
{
_name; = mediaData[Name];//getting from Json
_sex = mediaData[Sex];
_description = mediaData[Description];
}
return self;
}
@end
我的测试课
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "Media.h"
@interface ModelUnitTest : XCTestCase
@end
@implementation ModelUnitTest
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testModelObject:(id)file
{
XCTAssertNotNil(file);
XCTAssertTrue(file isKindOfClass:[Media class]]);
Media * fileObj = (Media *)file;
XCTAssertNotNil(fileObj.name);
XCTAssertNotNil(fileObj.sex);
XCTAssertNotNil(fileObj.description);
}
但是,这个测试永远不会运行 我知道我在这里犯了一些错误我错过了一些东西但无法弄清楚在这种情况下谁能帮助我
【问题讨论】:
-
NSString *描述;不是一个好习惯。看起来它指的是一个类而不是一个类的实例。
-
我在我的代码中更正了它,谢谢
标签: ios xcode unit-testing xctest