0

Я пишу UITest для моего проекта. Поэтому я хочу, чтобы несколько файлов были подклассифицированы в 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 

Может кто-нибудь сказать мне, как на модули/Создать несколько файлов UITesti ng классов.

+0

Пожалуйста размещаете код по крайней мере один из файлов с ошибкой – Oletha

+0

я добавил пример кода для обоих файлы. Прокомментируйте, пожалуйста. –

+0

Вы пробовали очистить проект и удалить полученные данные? – Oletha

ответ

0

Чтобы использовать несколько тестовых файлов UI, вы должны сначала создать файл заголовка для UITests.m, а затем в ваших отдельных тестовых файлах наследовать от UITest.h. Это даст вам setUp и tearDown методов от UITests.m в ваших подклассах. Все, что вам нужно сделать, это добавить новые методы тестирования в подклассы.

В качестве примера приведем пример наследнике UITests файла в Objective-C: https://gist.github.com/OffensivelyBad/012043f8dab50b3b024238e985462926

 Смежные вопросы

  • Нет связанных вопросов^_^