用多个Xctestcase类uitesting



我正在为我的项目编写最糟糕的案例。因此,我想将多个文件分类为Xctestcase,或者分类为我的其他测试类。每当我创建这样的文件时,我都会收到以下错误。

duplicate symbol _lastUsedSaveDirectory in:
/Users/UserName/Library/Developer/Xcode/DerivedData/ProjectName/Build/Intermediates/CodeCoverage/Intermediates/Project.build/Debug/Project_UITests.build/Objects-normal/x86_64/SecondaryFile.o
/Users/UserName/Library/Developer/Xcode/DerivedData/ProjectName/Build/Intermediates/CodeCoverage/Intermediates/Project.build/Debug/Project_UITests.build/Objects-normal/x86_64/MainFile.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试了以下内容,但没有任何可行的方法:

1. Created "SecondaryFile" by subclassing it from "MainFile" which is a subclass of "XCTestCase".
2. Created "SecondaryFile" by subclassing it directly from "XCTestCase".
3. Created both .h and .m file for both the "MainFile" and "SecondaryFile"

mainfile.m

#import <XCTest/XCTest.h>
@interface MainFile_UITests : XCTestCase
@end
@implementation MainFile_UITests
- (void)setUp {
        [super setUp];
        // Put setup code here. This method is called before the invocation of each test method in the class.
        // In UI tests it is usually best to stop immediately when a failure occurs.
        self.continueAfterFailure = NO;
        // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
        [[[XCUIApplication alloc] init] launch];
        // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}
- (void)tearDown {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        [super tearDown];
}
- (void)testExample {
    // Use recording to get started writing UI tests.
        // Use XCTAssert and related functions to verify your tests produce the correct results.    
}
@end

secondaryfile.m

#import <XCTest/XCTest.h>
@interface SecondaryFile_UITests : XCTestCase
@end
@implementation SecondaryFile_UITests
- (void)setUp {
        [super setUp];
        // Put setup code here. This method is called before the invocation of each test method in the class.
        // In UI tests it is usually best to stop immediately when a failure occurs.
        self.continueAfterFailure = NO;
        // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
        [[[XCUIApplication alloc] init] launch];
        // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}
- (void)tearDown {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        [super tearDown];
}
@end

有人可以告诉我如何模块化/创建多个文件uitesting类。

为了使用多个UI测试文件,您应该首先为UITests.m创建标头文件,然后在单独的测试文件中,从UITest.h继承。这将为您的子类中的UITests.m提供setUptearDown方法。然后,您要做的就是将新的测试方法添加到您的子类中。

作为一个例子,这是Objective-C中的子分类Uitests文件的示例:https://gist.github.com/offensiverbad/012043f8dab50b3b3b024238e985462926

最新更新