How to test launching a viewcontroller XCTest

て烟熏妆下的殇ゞ 提交于 2019-12-11 20:50:14

问题


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.

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

Thanks


回答1:


Using XCode 7, you can easily do UI tests:

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.

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.

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



来源:https://stackoverflow.com/questions/31491713/how-to-test-launching-a-viewcontroller-xctest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!