samedi 4 août 2018

Should functional test just assert responses only?

I have some confused question about testing.

We're using Slim as framework of the system. As I know, Unit Test is the minimum of testing. For example, to test if the class or method works as expected.

To test another functions of the system, for example, the system provide an API to search products information, this search function designed by the following thoughts:

  1. Clients post keyword to the API entry. eg. /search
  2. Handle the request and inject SearchService into the controller.
  3. Set the keyword to the SearhService.
  4. Push the keyword into the database. eg. search_history.
  5. Fetch the search result back to controller, and response to clients.

This is how search API designs.

And we created a functional test for the Search API called SearchTest. This is how we done:

  1. Use $this->runApp() method provided by Slim to sending requests to the API entry.
  2. Set several test cases to test different kind of scenario, such as "No keyword provided", "No search result" ... etc.
  3. Assert the responses that return value or HTTP status as expected.

Some questions are confusing:

  • Sending requests and asserting the responses, is that all? Do we misunderstand so called "functional testing"?
  • We shouldn't care about how it works, we just need to send request and assert the responses, right?
  • If not, should we check dependencies or used components work as expected? For example, should we connect to the database, and check if the keyword pushing success or not?

Aucun commentaire:

Enregistrer un commentaire