I'm looking for some advice writing tests for my S...
# ktor
z
I'm looking for some advice writing tests for my Subsonic API client. At the moment I've just been passing the expected response body as a parameter in a helper function that I created, which my MockEngine returns. Pretty much it's only testing that my custom serialization works. The issue though is it dramatically increases how big my test files are. The responses are all json, with some being nearly 100 lines long, and with over 70 endpoints it quickly adds up. I'm wondering if there's a better way of doing this. I think I could store the json responses in resources and load that to clean it up a bit. Another big issue is Subsonic API is just really poorly designed, some endpoints not being implemented on some clients.
s
I'm not used to Subsonic API but if I'm in this situation, I think I would setup and run Subsonic-compatible server locally (using testcontainer or docker compose, etc) and run test with client. In this way, I believe you can also check compatibility between subsonic client and server implementations (Navidrome, Gonic, ...) Mocking every endpoint is not ideal IMO.
☝️ 1
r
Wire mock recording/replay feature could be really nice for this too. I typically create an interface in front of all my external api clients, and then use wire mock to test my api client against that interface which just ensures the actual api client properly implements interface and ensures that the actual api client is configured correctly, parses/serializes correctly etc etc. The I create a fake implementation(or you can use a mocking library) that will make it easy and fast to stub out functionality throughout my tests.
Oh and I typically don't test api clients if the api client package already provides an interface and is testing correctly to that interface, or if the client is auto generated from like openapi or something.