Unit-testing – Testing front-end app that hits a REST service

integration-testsresttestingunit testing

A lot of questions about testing here… And I have another one. Forgive me, but I want to make sure I do this right.

Let's say I have a front-end application, be it a mobile app, or a single-page website, or anything else. This app hits a REST service, that I also develop. The service fetches data from 3rd party REST APIs, processes this data, and returns the results to the application.

My service is well tested and developed in a hexagonal manner, with comprehensive black-box unit tests (canned data) and few integration tests (hitting 3rd party services) to see that adapters are working ok with ports (see here).

My front end is also well tested with unit tests and mock data (it doesn't really hit the service in tests). I feel though that it would be nice if it was tested together with the service I develop. The few things I am unsure of:

  1. Should I be using canned data when testing my service, or should I be hitting 3rd party APIs in the tests?
  2. Should these be comprehensive automated tests (provided that all functionality is already tested with canned data on front end, and the service is really well tested too, so a lot of these tests would be testing what's already tested), or should it be just few manual tests, like hitting some buttons and seeing if the data comes through? Here I am mainly thinking about the cost/benefit ratio.
  3. Are there any frameworks to write comprehensive automated tests like that?

I am sure many of you were in similar situation. So it would be great to get some advice. If you can link a white paper or a conference about the subject, it would be even better. Thanks in advance for any suggestions.

Best Answer

If you do not own the REST API's, your responsibility ends with them

You need tests that check if your application calls the API under your control correctly. Therefore, use the actual application with the actual service (the one you control) but calling mocked services (the ones you don't control).

So...

  1. Use canned data for the services you don't control, pipe that data into your actual service and then use that from your application.
  2. This should be a very broad test to simply check if calls from your application go through to the service. At this point you should already have thoroughly tested your application with the responses your service might return and you should have thoroughly tested your service with the responses the services you can't control might return. All of this preferably automated. Depending on the amount of releases you do it might be easier to test this manually just prior to release.
  3. Depends on the technology used, which might not make this the best website for that question.