ios - How to mock data in UITest on Xcode 7? -


someone has tried include mock data new xcode 7 ui tests?

  • have used specific framework?
  • how have managed targets?

i think there lot of ways approach 1 - difficulty apple has intentionally designed uitests run entirely separate app under test. said, there few hooks can use coordinate logic in app logic in tests feed in mock data or alter behavior of app in way. 2 have found useful launchenvironment , launcharguments.

in test - xcuiapplication().launcharguments corresponds nsprocessinfo.processinfo().arguments in app code

likewise: xcuiapplication().launchenvironment -> nsprocessinfo.processinfo().environment

launchenvironment straight forward dictionary whereas launch arguments array. in test can feed values either of these parameters before launch app:

let app = xcuiapplication() app.launchenvironment["-fakedfeedresponse"] = "success.json" app.launch() 

then in application logic can switch on these values like. like:

func fetchfeed() -> json {     if let fakedjsonfilename = nsprocessinfo.processinfo().environment["-fakedfeedresponse"] {         let fakepayload = fakedatafilenamed(fakedjsonfilename)         return fakepayload     } else {        //make network call , return real json payload      } } 

using pattern faked/mock data need files included members of app target.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -