2015-11-05 49 views
0

我有一個用許多測試方法的UI測試類,當運行第一個測試時,我需要在我的應用程序上進行登錄,並且我不需要以下方法,因爲測試不會重新安裝應用程序。如何知道哪個UI測試在類中運行?當第二個測試開始

所以,我試圖在我的類上創建一個變量布爾值,但在每次測試的時候都會重新創建var。

我知道這些測試是由字母順序運行,但我認爲這是沒有的事,我想確保我的第二次測試運行和第三,等一個好辦法...

有誰知道如何幫助我?

回答

1

在你UItestFile,創建一個屬性的loggedIn

@interface UITests() 
@property (nonatomic,assign) BOOL loggedIn; //use this to know wether user is logged in or not 
@end 

-(void)testLogin 
{ if //user logged set the loggedIn flag and skip the test 
    { self.loggedIn = YES; 
    return; 
    } 
else 
    //perform login and test login flow 
} 

測試並不一定按照字母的運行,改變測試的順序,你可以使用testInvocation,總是先打電話TESTLOGIN。

+ (NSArray <NSInvocation *> *)testInvocations 
{ 
    NSArray *testNames = @[@"testLogin", 
          @"testY", 
          @"testB", 
          @"testC", 
          @"testA", 
          ]; 

    NSMutableArray *result = [NSMutableArray array]; 
    for (NSString *testName in testNames) 
    { 
     SEL selector = NSSelectorFromString(testName); 
     NSMethodSignature *methodSignature = [self instanceMethodSignatureForSelector:selector]; 
     NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; 
     invocation.selector = selector; 
     [result addObject:invocation]; 
    } 
    return result; 
} 
+0

用於SWIFT探險,的loggedIn屬性(非可選的類型)需要被定義的靜態屬性類型,因爲每XCTest實例測試類的新實例對於每個測試()方法和實例變量將被複位到其默認值。 – Sushant

相關問題