Posts

Showing posts with the label data-driven tests

Pytest Tutorial 7 | Intermediate - Fixtures in Detail

In this tutorial, we'll explore one of the most powerful features of Pytest: fixtures. Fixtures allow you to set up the environment your tests need, making them more reliable and easier to maintain. We'll cover what fixtures are, how to create and use them, and tackle advanced topics like fixture scope, lifetime, and combining fixtures with parameterization. 1. What are Fixtures? Fixtures in Pytest are functions that manage the setup and teardown of resources needed by your tests. These could be anything from database connections to temporary files or even mock APIs. Using fixtures ensures that your tests start from a clean state and can be isolated from one another, which is crucial for consistent and reliable testing. 2. Creating and Using Fixtures Let's look at how to create a fixture and use it in a real-world scenario, such as testing an API client. Example: API Client Fixture Imagine you’re writing tests for a web application that interacts with a third-party API. You...

Pytest Tutorial - 5 | The Basics - How to write data-driven tests?

Image
So far we have understood how to write simple tests in pytests . We also saw pytest in action. In this tutorial we will now learn how to write data driven tests. What are data driven Tests? These are those tests, which tests a functionality using various scenarios mocked through a set of test data. In order to achieve this we pass the test data from external data sources such as csv/excel/yaml/json/database/etc. Now why do we need to pass test data from an external data source? Very simple reasons: If the test data is not passed through an external data source, then everytime we add/update/remove test data, we need to update our code. One test case can be tested using multiple combinations of data to test for various conditions of validation Example 1: you can test login using 2 types of test data   Valid credentials Invalid credentials      Example 2: you can also test password change functionality with 6 types of test data : (Minimum - 1) allowed length of passwo...