Hello everyone!
I was never good at testing networking code, because most of my networking projects were too simple to test its networking tasks (overall they were simple, I am starting with bigger projects now).
Now, I am facing a bigger projects, where I need to wrap an API of self-hosted service and I don’t want to have external project to test it, I want to test it where it should be - in Tests folder. I decided to not mock URLSession, but instead of that I have added to project docker-compose file with settings ready for testing. The problem is when I start all tests (CMD + U) most of the tests are failing, but when I run them individually, one by one they all pass. I am not sure if using semaphore here is a good choice, so I want to ask You what would You do with my issue. I am using Combine (at least I am trying to use it, I am pretty new in reactive programming and even after reading book about Combine I still doesn’t feel it to use it in the whole project).
And when we are talking about testing APIs, I would like to ask You one more thing. I am writing a project, which again will use 3rd party API, but here the huge problem is that API is unpredictable, I have to manually acquire 4 tokens (one after one, where the last is the one that I need, rest are just “verification process” to get the last one). It throws different objects (and sometimes they’re nested just to annoy developers) and they can look like that:
struct Child {
let name: String?
let id: Int?
let parent: String?
let url: String?
}
It’s just an example (all of these keys can be either present or absent). If I Child
is nested in other object, it contains only ID and URL, but when I call that URL I am getting everything except URL (it’s in JSON, but it’s outside of that object).
That API has a lot of dependencies and weird behaviors. I would love to see some tips in testing and just in developing that wrapper.
Most of You will probably ask why I am doing that:
- Applications for iOS of these two are just bad and I want to write them in my way with Swift (none of them are using it, especially the second API where its app is just wrapped web application which works horrible).
- I don’t have any other ideas for apps useful for me
- I have a lot of time for development and I can’t find job (I don’t have any real experience).
Sorry for putting two questions in single topic, but I think that it will be better than separating that on two different topics.
Thanks!