如何测试启动ViewController XCTest [英] How to test launching a viewcontroller XCTest

查看:90
本文介绍了如何测试启动ViewController XCTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在测试的框架,我想从公共接口测试一个方法,用户将调用该方法以显示带有xib的ViewController,我想使用XCTest对这种情况进行单元测试,调用执行上述内容的方法,像这样

I have a framework under test, I want to test a method from public interface which user will call to show a ViewController with xib, I want to unit test this situation using XCTest, call to the method which does above described thing looks like this

testClass = [[AdGateMedia alloc] initWith:@"nac" and:@"1234" withParent:view];
[testClass showView];

父视图控制器是从正在使用框架的主机应用程序中调用视图控制器的实例.

The parent view controller is instance of calling view controller from host application which is using framework.

在测试时,此父参数必须使它能够呈现新的控制器.

When testing this parent argument needs to be such that it will allow presenting of new controller possible.

有两件事1.是否可以进行上述测试?2.如果是,如何在iOS下使用XCTest进行操作?

There are two things 1. Is above type of testing possible ? 2. If yes how to do it using XCTest under iOS ?

谢谢

推荐答案

使用XCode 7,您可以轻松进行UI测试:

Using XCode 7, you can easily do UI tests:

文件->新建->目标-> iOS->测试iOS UI测试包

File -> new -> target -> iOS -> Test iOS UI Testing bundle

生成的代码具有一些使用方法的提示.基本上,您将光标置于测试方法中,然后单击红色的记录按钮.

The generated code has some hints how to use it. Basically you place the cursor in your test method and then hit the red record button.

因此,您可以模拟(几乎)任何用户操作.当您为可访问性命名UI元素时,生成的代码更具可读性.

So you can simulate (almost) any user action. The generated code is more readable, when you name the UI elements for accessibility.

在这种情况下,您可以在正在运行的(示例)应用程序中使用您的方法.

In your case, you use your method in a working (example) application.

(在XCode 7之前就可以实现,但是使用XCode 7确实很容易做到)

(it has been possible before XCode 7 but with XCode 7 it's really easy to do)

这篇关于如何测试启动ViewController XCTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆