我想知道UIViewcontroller
是如何知道需要選擇哪個測試文件的。ViewController如何識別哪個測試類需要運行:潛意識框架
E.g.我有一個很大的項目,其中有很多UIViewcontrollers
。
我想爲每個控制器製作單獨的測試文件。像登錄,另一個爲配置文件UIViewcontroller
。
我知道框架是在早期階段,但任何幫助表示讚賞。
謝謝。
我想知道UIViewcontroller
是如何知道需要選擇哪個測試文件的。ViewController如何識別哪個測試類需要運行:潛意識框架
E.g.我有一個很大的項目,其中有很多UIViewcontrollers
。
我想爲每個控制器製作單獨的測試文件。像登錄,另一個爲配置文件UIViewcontroller
。
我知道框架是在早期階段,但任何幫助表示讚賞。
謝謝。
在潛意識中,測試驅動您的應用程序,而不是相反。您肯定可以進行與不同視圖控制器相對應的測試,但測試負責導航到應用程序內的這些控制器視圖。
該導航通常在-setUpTest
的測試實現中完成。假設您的應用程序打開到「主頁」屏幕,其中有一個標題爲「登錄」的按鈕;並且按下該按鈕會導致出現「登錄視圖控制器」。你想測試視圖控制器的方法是這樣的測試添加到您的集成測試目標:
@interface LoginTest : SLTest
@end
@implementation
- (void)setUpTest {
// make sure we're at "Home", then:
SLButton *loginButton = [SLButton elementWithAccessibilityLabel:@"Log in"];
[loginButton tap];
}
/*
now test the login view controller:
- (void)testThat... { }
*/
- (void)tearDownTest {
// log out and go back to "Home"
}
@end
請注意,這是結束在已知位置非常重要的,你的測試開始,在-setUpTest
和-tearDownTest
,分別 - 你不能依靠以特定順序執行的潛意識測試。
那麼如何測試配置文件屏幕呢?比方說,在你的應用程序,該配置文件顯示在登錄後立即接着,簡檔測試將是這個樣子:
@interface ProfileTest : SLTest
@end
@implementation
- (void)setUpTest {
// Log in
}
/*
now test the profile view controller:
- (void)testThat... { }
*/
- (void)tearDownTest {
// log out and go back to "Home"
}
@end
你看到ProfileTest
應該做的,它需要得到的觀點是想要測試 - 在這種情況下,登錄。(這就是爲什麼LoginTest
註銷並返回到-tearDownTest
中的「home」,這樣ProfileTest
將從已知狀態開始,即使LoginTest
首先執行)也很重要。
爲了使這個設置過程更容易,您可以使用「應用程序鉤子」。通過LoginTest
驗證登錄用戶界面的工作原理,ProfileTest
通過該用戶界面並不重要。相反,它可以讓應用程序登錄權之前,你的應用程序委託推出的測試中,它可能會註冊一個「登錄管理器」單身爲能夠在編程方式登錄測試用戶:
[[SLTestController sharedTestController] registerTarget:[LoginManager sharedManager]
forAction:@selector(logInWithInfo:)];
然後,-[ProfileTest setUpTest]
可以打電話:
[[SLTestController sharedTestController] sendAction:@selector(logInWithInfo:)
withObject:@{
@"username": @"[email protected]",
@"password": @"Hello1234"
}];
你是什麼意思**控制器**測試文件**? – AtWork