0

J'écris des cas UITest pour mon projet. Je veux donc avoir plusieurs fichiers sous-classés dans XCTestCase ou sous-classés dans mes autres classes de test. Chaque fois que je crée un tel fichier, j'obtiens l'erreur suivante.UITesting avec plusieurs classes 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) 

J'ai essayé ce qui suit, mais rien ne fonctionne:

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 

Quelqu'un pourrait-il me dire comment modularisation/Créer plusieurs fichiers UITesti ng classes.

+0

S'il vous plaît code postal d'au moins l'un des fichiers de l'erreur – Oletha

+0

J'ai ajouté un exemple de code pour les deux Des dossiers. Commentez s'il vous plaît. –

+0

Avez-vous essayé de nettoyer le projet et de supprimer vos données dérivées? – Oletha

Répondre

0

Pour utiliser plusieurs fichiers de test d'interface utilisateur, vous devez d'abord créer un fichier d'en-tête pour UITests.m, puis dans vos fichiers de test séparés, hériter de UITest.h. Cela vous donnera les méthodes setUp et tearDown de UITests.m dans vos sous-classes. Tout ce que vous avez à faire est d'ajouter vos nouvelles méthodes de test à vos sous-classes.

À titre d'exemple, voici un exemple d'un fichier UITests sous-classé en Objective-C: https://gist.github.com/OffensivelyBad/012043f8dab50b3b024238e985462926