The Github API is your starting point for testing and validation because it's outside your control and is well-documented for proper behavior, return data structures, and response codes.
- [Instructor] Next, let's talk about the API that we'll be testing and validating today. Realistically, you could use any API, but we're going to use GitHub. GitHub has some drawbacks, but it's useful here because anyone, anywhere can sign up. The vast majority of the features are available for free. And odds are, you're familiar with most of the concepts. After this course, switching these lessons learned to other third party APIs, or even your internal APIs, should be straight forward. I've helped people accomplish similar with internal APIs, in addition to systems like Twilio and Salesforce.
But we're not going to test and validate the entire GitHub API, we're only going to worry about validating search, authentication, and reading and writing from Repositories. Yes, there are many other things we could test. Yes, a full testing suite should cover all those. But if you start down that path, there's no way back. There's always another thing to test. There will always be another possible error condition, there will always be another use case. But more importantly, you quickly approach the point of diminishing returns.
But this gets to my first philosophical point about APIs. Odds are, you aren't using all of it. Why should you test functionality that you, or your customers, never use? Therefore, we're not going to worry about the entire API, just the parts that are based on use cases we're actually trying to satisfy. So should you fully test your API? Absolutely. You should test it to the best of your ability. Where things are a little different, is how you validate it's behavior from the outside.
In that case, you should use the primary use cases, that you identified as the primary test cases. If you can demonstrate and validate that your API solves the purposes it was designed for, that's a good thing. And if you need a primer on API design, check out Effective Design of RESTful APIs in the course library.
- The benefits of behavior testing
- Setting up a test environment
- Building your first API test
- Sending requests
- Validating response codes and payload
- Making authenticated requests
- Refactoring tests
- Writing to the API
- Establishing a system state for tests
- Using extensions
- Performing batch operations