I'm creating a test suite for a test that should check that a specific API Service is available. So I'm confused on exactly how I can check the availability of a service. Is it sufficient to only check the status code to be 200 or are there other ways to confirm that?
See also sqa.stackexchange.com/a/40043/8992– Michael DurrantSep 25, 2019 at 10:09
1You mean if the service available in production?– beatngu13Sep 25, 2019 at 20:02
It depends on how you define "available". Making a simple call and checking that you get a code 200 means the servers is up and it can recieve calls.
Now if the API uses for example a database then the simple call might not detect underlying systems are wrongly configured.
Personally I would want to ensure the API and its depencies are working. So doing a call that actually does something and verifying the result would make more sense. But you might not want to call API's that insert/change data.
I would suggest to ask the developers to add a HealthCheck method, that checks the internals of the API and gives a small json report to check.
I think service availability shouldn't be addressed with traditional testing. When would the corresponding tests run? Per hour, per minute, … ?
Instead, monitoring is the way to go. You can use tools such as Uptime Robot to receive alerts whenever a service is down. In addition, use something like Sentry to be notified when internal exceptions occur.
Add the site UptimeControl.net to the article, because only they have a 3-minute site availability check interval on the free plan.