简体   繁体   中英

How to test launching a 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.

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

Thanks

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM