OHHTTPStubs icon indicating copy to clipboard operation
OHHTTPStubs copied to clipboard

How to use in a UITest

Open tagy opened this issue 2 years ago • 9 comments

New Issue Checklist

Environment

  • version of OHHTTPStubs: 9.1.0
  • integration method you are using:
    • [ ] Cocoapods
    • [ ] Carthage
    • [ ] submodule
    • [ x] other: SPM
  • version of the tool you use: Xcode 12.5

Issue Description

I am using OHHTTPStubs in my Units tests without any issue. For my unit tests target I have my main app selected as the host application. I have OHHTPStubs added under link with libraries for the unit testing target.

For my UITest target I have my main app selected as the target app. I have also added OHHTPStubs under link with libraries for the UI testing target.

I am able to import OHHTTPStubs in to my UITest files and can add code to stub out requests. But when I run a UITest the stub blocks are never called.

I do not have OHHTTPStubs added under link with libraries for my main app.

I have seen this guide but not sure if it applies to my issue A tricky case with Application Tests

I think the setup I have is applying the stubs only to my UITesting app, and not the main app.

Any help would be appreciated thanks.

tagy avatar Jul 27 '21 11:07 tagy

Having the same issue here.

LemonSpike avatar Aug 30 '21 18:08 LemonSpike

having the same issue here. I'm using Xcode 13

anelrh26 avatar Oct 07 '21 00:10 anelrh26

What I have done in my project

  1. Include OHTTPStubs, and sample JSON in my main bundle.
  2. To make sure the sample JSON is not pushed to production I use a different target for production and another one for all other builds. hence all the sample JSON are not a part of production build.
  3. Use environment variable and check for the environment variable if passed then mock the API calls.
  4. The environment variable check code is under IF Debug compiler flag hence that does not ship to production either.
  5. Now this environment variable can be passed in the UI test as launch arguments when launching the application in the UI test. Hope this helps. Let me know for any more info.

kishorepran avatar Nov 14 '21 08:11 kishorepran

Same issue :(

ppamorim avatar Sep 27 '22 12:09 ppamorim

Same issue :(

Can you create a repo for your sample project and share link here. I would love to debug your issue and submit a pr. thanks

kishorepran avatar Sep 27 '22 16:09 kishorepran

What I have done in my project

  1. Include OHTTPStubs, and sample JSON in my main bundle.
  2. To make sure the sample JSON is not pushed to production I use a different target for production and another one for all other builds. hence all the sample JSON are not a part of production build.
  3. Use environment variable and check for the environment variable if passed then mock the API calls.
  4. The environment variable check code is under IF Debug compiler flag hence that does not ship to production either.
  5. Now this environment variable can be passed in the UI test as launch arguments when launching the application in the UI test. Hope this helps. Let me know for any more info.

Hi @kishorepran, so how about my JSON file? All of them put in main bundle? I think it will improve the app's size.

Wiley-Wan avatar Jul 14 '23 03:07 Wiley-Wan

@Wiley-Wan : Please refer to point 2

kishorepran avatar Jul 15 '23 06:07 kishorepran

Same. Couldn't use it with my UITest

sulaimansust avatar Mar 26 '24 13:03 sulaimansust

Hi @sulaimansust , @Wiley-Wan : Please upload a sample project where this is not working and let me raise a pr with working example.

kishorepran avatar Mar 29 '24 06:03 kishorepran