Ios Viewcontroller如何识别需要运行的测试类:潜意识框架

Ios Viewcontroller如何识别需要运行的测试类:潜意识框架,ios,testing,automation,subliminal,Ios,Testing,Automation,Subliminal,我想知道UIViewcontroller是如何知道需要选择哪个测试文件的 例如,我有一个很大的项目,里面有很多UIViewcontrollers 我想为每个控制器制作单独的测试文件。类似于1表示登录,另一个表示配置文件 我知道该框架尚处于早期阶段,但非常感谢您的帮助 谢谢。在潜意识中,测试驱动应用程序,而不是相反。您当然可以有对应于不同视图控制器的测试,但是这些测试负责导航到应用程序中这些控制器的视图 该导航通常在-setUpTest的测试实现中完成。假设您的应用程序打开到“主页”屏幕,屏幕上有

我想知道
UIViewcontroller
是如何知道需要选择哪个测试文件的

例如,我有一个很大的项目,里面有很多
UIViewcontrollers

我想为每个控制器制作单独的测试文件。类似于1表示登录,另一个表示配置文件

我知道该框架尚处于早期阶段,但非常感谢您的帮助


谢谢。

在潜意识中,测试驱动应用程序,而不是相反。您当然可以有对应于不同视图控制器的测试,但是这些测试负责导航到应用程序中这些控制器的视图

该导航通常在
-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
-teardownstest
中-您不能依赖于以特定顺序执行的潜意识测试

那么,您将如何测试配置文件屏幕呢?比方说,在您的应用程序中,该配置文件在登录后立即显示。然后,配置文件测试将如下所示:

@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
注销并返回
-teardownstest
中的“主页”非常重要的原因,以便
ProfileTest
将从已知状态开始,即使
LoginTest
首先执行)

为了简化此设置过程,您可以使用“应用程序挂钩”。通过
LoginTest
验证登录用户界面是否正常工作,
ProfileTest
通过该用户界面并不重要。相反,它可以要求应用程序登录。在您的应用程序委托启动测试之前,它可能会注册一个“登录管理器”单例,以便能够以编程方式将测试用户登录到:

[[SLTestController sharedTestController] registerTarget:[LoginManager sharedManager] 
                                           forAction:@selector(logInWithInfo:)];
然后,
-[ProfileTest setUpTest]
可以调用:

[[SLTestController sharedTestController] sendAction:@selector(logInWithInfo:)
                                         withObject:@{
                                                        @"username": @"john@foo.com",
                                                        @"password": @"Hello1234"
                                                     }];

在潜意识中,测试驱动应用程序,而不是相反。您当然可以有对应于不同视图控制器的测试,但是这些测试负责导航到应用程序中这些控制器的视图

该导航通常在
-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
-teardownstest
中-您不能依赖于以特定顺序执行的潜意识测试

那么,您将如何测试配置文件屏幕呢?比方说,在您的应用程序中,该配置文件在登录后立即显示。然后,配置文件测试将如下所示:

@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
注销并返回
-teardownstest
中的“主页”非常重要的原因,以便
ProfileTest
将从已知状态开始,即使
LoginTest
首先执行)

为了简化此设置过程,您可以使用“应用程序挂钩”。通过
LoginTest
验证登录用户界面是否正常工作,
ProfileTest
通过该用户界面并不重要。相反,它可以要求应用程序登录。在您的应用程序委托启动测试之前,它可能会注册一个“登录管理器”单例,以便能够以编程方式将测试用户登录到:

[[SLTestController sharedTestController] registerTarget:[LoginManager sharedManager] 
                                           forAction:@selector(logInWithInfo:)];
然后,
-[ProfileTest setUpTest]
可以调用:

[[SLTestController sharedTestController] sendAction:@selector(logInWithInfo:)
                                         withObject:@{
                                                        @"username": @"john@foo.com",
                                                        @"password": @"Hello1234"
                                                     }];
控制器的测试文件是什么意思?控制器的测试文件是什么意思?