Learn the principles of a good test and how to apply them to test your network code.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4001919-how-to-make-an-app-like-instagram-in-ios/lessons/13
Learn the principles of a good test and how to apply them to test your network code.
How can I solve the error at 15:00???
When I run the test again at that point, the test succeeds. What are you seeing?
I had the exact same issue as the video at 15:00
If you click the red X by the name of the test, to run it again, does the test then pass?
nopeā¦ the error stays though
If youāre running with a test server, make sure the server is going. Try pulling up the url in a browser.
I set up the project totally according to the tutorial video though.
Copy pasting the code from project gives me the following screenshot.
Hmm, what is the URL I should be inputting in my browser for server.GET[ā/api/v1/postsā] = { _ in HttpResponse.ok(.text(JsonData.goodFeed)) }
Sorry, I wasnāt at my computer before and was trying to help from memory. Donāt worry about opening it in your browser. I would try adding a breakpoint in APIClient.publisherForRequest
. See what youāre getting from the request and why itās returning an error. If youāre not able to solve it, zip up your project and Iāll see if I can take a look.
Petstagram.zip (60.0 KB)
Uploaded, thank you so much TwT
Sorry for the delay, Iāve been traveling.
Ok, before I give you the issue, letās go down a couple of troubleshooting paths.
Try setting a breakpoint on line 46 in APIClientTests. Step into publisherForRequest
and look at the URL that is being requested. Since there is no external server, this is the URL that Swifter will be serving up for the test. Double check that Swifter is setup to serve that URL.
In setUpWithError
, we add a notFoundHandler
to the server. This helps by checking for URLs that are requested, but not found. The feedback is given through an attachment to the test. You can see this by opening the Report Navigator in the left panel and clicking on the failed test run. You should see āAdded attachment named āUnhandled API path requestedāā. Expand that and click the quick look icon (looks like an eye). That will show the text from the attachment.
Now, this gives us clues, but youāve stumbled on a pretty tricky bug. The issue is that the test is passing the local
environment to APIClient
and that is where the baseUrl
comes from. If you look closely, thereās a typo in that string - āap1ā instead of āapiā. Theyāre so close itās hard to notice. If you change the ā1ā to an āiā, your test will pass.
I canāt be the only one who got Cannot find 'JsonData
in scope` as an error, can I? I followed the video to a T but am getting this error in PostRequestTests.swift.
Make sure JsonData is selected for the PetstagramTests target. If that is selected and your build is still giving you errors, send me a zip of the project and Iāll take a look.
Hi,
I get this error when trying to run or preview the app.
Iām currently trying to do the add comment challenge but it started on the UnitTest lesson
Not sure how to handle this. Can anyone please help?
Can you send me a zip of your project? It may be that Swifter has changes. Give me a few days and Iāll investigate.
Iām using the final version of Episode 17 in the course material: 17-challenge-comment-challenge.
Iām new here and cannot upload more attachments. Do you have an email addresses I can send it to?
Thanks,
Michal
Ok, it looks like on Sept 28th they committed a breaking change to Swifter. The easiest fix is to change .notFound
to .notFound()
. If you want to make sure youāre using the same version of Swifter as I used, you can change the Swifter package dependency to 1.4.7.