3

Our team is doing ATDD(Acceptance Test Driven Development) for our projects.

And I have a question.

I write API tests like below.

1) creating fixtures

2) sending headers, query, path, body to endpoint.

3) assert response of status code, body, etc

And here is the question!

Should I write all test cases for exceptional case (like invalid body field and value combinations) in acceptance tests?

For example, POST /users receives body like { name: "steve", age: 27, account: "test", password: "test1234" }

Do you write test cases for all body input combinations? (If name is empty, return 400 / If name is too short, return 400 / If age is not number, return 400 / If password does not contain number, return 400 and so on)

There are too many cases:(

If you don't, can you share with me how you deal with this?

1 Answers1

1

You do need to cover those cases, but you don't want to cover them all at high levels. In order to write fast and maintainable tests you need to follow test pyramid writing a lot of low-level (unit) tests and few high-level (system) tests.

So what you want to do is check all the validation rules in unit tests (for each field) and then create only 1 high-level negative test per endpoint to check that validation is invoked and the error format is correct.

Stanislav Bashkyrtsev
  • 14,470
  • 7
  • 42
  • 45