我创建了以下XCTestCase超类:
// FileNameTest.h
#import <XCTest/XCTest.h>
NS_ASSUME_NONNULL_BEGIN
@interface FileNameTest : XCTestCase
@end
NS_ASSUME_NONNULL_END
// FileNameTest.m
#import "FileNameTest.h"
@implementation FileNameTest
- (void)setUp {
[super setUp];
}
- (void)tearDown {
[super tearDown];
}
- (void)helloMessage{
NSLog(@"Hello");
}
@end
和一个调用超类方法的子类:
// FilenamePatternTest1.m
#import "FileNameTest.h"
@interface FilenamePatternTest1 : FileNameTest
@end
@implementation FilenamePatternTest1
- (void)testExample {
[self helloMessage];
}
@end
但是子类不会编译。错误消息显示为:
'FilenamePatternTest1'的无可见@interface声明了选择器'helloMessage'
Objective-C看不到.m
文件中的声明。您将需要在超类的.h
文件中声明要调用的方法。