JSON-based APIs
Learn how to test a JSON based API.
We'll cover the following...
What will controller tests cover?
We strive to keep our controllers as small, with as little branching logic as possible. This accomplishes two goals:
-
As few test cases as possible.
-
Business logic is kept out of the web part of our application.
The logic for most controller actions can be tested with two tests: a happy path test and an error case test.
Note: There will always be exceptions to this, but it should be your starting goal.
Lastly, beyond testing the logic in the actions themselves, we may need to include tests to verify that certain plugs are included in our application’s call stack. For that, we’ll test for:
- A JSON-based endpoint