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:
- Clients post keyword to the API entry. eg.
/search
- Handle the request and inject
SearchService
into the controller. - Set the keyword to the
SearhService
. - Push the keyword into the database. eg.
search_history
. - 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:
- Use
$this->runApp()
method provided bySlim
to sending requests to the API entry. - Set several test cases to test different kind of scenario, such as "No keyword provided", "No search result" ... etc.
- 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