Section Wrap Up | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Schema Validation
Instructor: Artem Bondar
Lesson Summary
This section wraps up the discussion on schema validation versus regular assertions in API testing. When to Use Schema Validation Use schema validation after every single response. This method is straightforward and helps ensure that your API does not have integration issues. You can recreate the schema and run the schema test repeatedly. When to Use Assertions Use assertions when you want to validate specific properties that were modified during the test. For example, in the test for creating and deleting an article, you should: Use schema validation for the overall response. Use assertions only for the properties you changed, such as title , description , and body . There is no need to validate properties that were not impacted by your test, such as the date, author, or favorites. The schema validation will cover those aspects. General Rule If your test involves a functional operation and you made changes, validate the result of that action. For all other properties, rely on schema validation, which is typically sufficient. In summary, use schema validation for comprehensive checks and assertions for specific changes made during tests. This approach will streamline your testing process.
Video Transcript
All right, guys, this is a quick section wrap-up and let's talk about when to use schema validation and when not, and when use the regular assertion. So the answer here is simple. Use schema validation after every single response. This is so easy and so simple way to validate that your API most likely doesn't have integration issues. You can recreate the schema and run the schema test again and again. When to use the assertion because you don't want to create the properties for every single property inside of your response. So let's look in our current test, create and delete the article. So as I mentioned before, after every single test, you have to add the should match schema after every single response. But you need to add the assertions like this only to the properties that you modified during the test. For example, here in the test create and delete the article, we created the article with the three values, title, description, and body with three values. When we make the assertion, we only need to validate those three values because we created those, and we need to validate did API actually created those specific values. But we don't care about anything else. We don't care about the date, we don't care about the author, we don't care about the favorites, we don't care all the stuff that we did not actually impacted during our test execution. The rest of the stuff, the schema we'll take care about. That's the pretty much simple rule. So if your test involves any functional operation and you made this functional action, validate result of your action. For everything else, just use schema validation, it will be more than enough. Trust me. So that's all I wanted to say about the assertions, about the schemas, and that's it. See you in the next lesson.