Overview of data-driven testing

By employing the data-driven testing approach, we can use a single test to verify different sets of test cases or test data by driving the test with input and expected values from an external data source instead of using the hardcoded values every time a test is run. This becomes useful when we have similar tests that consist of the same steps but differ in the input data and expected value or the application state. Here is an example of a set of login test cases with different combinations:

Description Test data Expected output
Test valid username and password A pair of valid usernames and passwords The user should log into the application with a success message
Test invalid username and password An invalid username and password The user should be displayed the login error
Valid username and invalid password A valid username and an invalid password The user should be displayed the login error

We can create a single script that can handle the test data and the conditions from the preceding table. By using the data-driven testing approach, we separate the test data from the test logic by replacing the hardcoded test data with variables using the data from external sources, such as CSV or a spreadsheet file. This also helps to create reusable tests that can run with different sets of data, which can be kept outside of the test. Data-driven testing also helps in increasing the test coverage, as we can handle multiple test conditions while minimizing the amount of test code we need to write and maintain.

The benefits of data-driven testing are as follows:

  • We can get greater test coverage while minimizing the amount of test code we need to write and maintain
  • It makes creating and running a lot of test conditions very easy
  • Test data can be designed and created before the application is ready for testing
  • Data tables can also be used in manual testing

Selenium WebDriver, being a pure browser-automation API, does not provide built-in features to support data-driven testing. However, we can add support for data-driven testing using testing frameworks such as JUnit or TestNG. In this book, we are using TestNG as our testing framework and we will use parameterization features of TestNG to create data-driven tests in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.105.105