What is it?

A data-driven test (a.k.a. parameterized test) is a test designed to accept one or more parameters that are used in the test. It is expected that the test will be run multiple times and each iteration will be provided different values for the parameters. The parameters are typically used to vary the user inputs and to check the output.

Using MuseIDE, there are two steps from a single (working) test to set of tests driven by a set of data values:

  1. Parameterize the test
  2. Build the data table
  3. Create a parameterized test suite

Parameterize the test

Even if a test will not be used with multiple input/output values, parameterizing a test also serves to document what user inputs go into the workflow and what values are expected as output from the system.

So in the Wikipedia search test, I want to parameterize the search term giraffe and the expected page title. First step is to replace those constants with variable references:

test1-parameterized.png

After this change, the test will lookup variables named search_term and expected_page_title and use them in the user input and page title verification steps.

If I ran the test now, it would fail because those variables would be undefined. So now I will define default parameters for the test. These will be injected into variables when the test starts. You can do this on the Parameters tab in the test editor:

test1-parameters.png

Now when the test runs, these values will be injected into variables that can be accessed in test steps. Try running the test. If you examine the event log, you will find events as the variables are set at the beginning of the test and as the variables are resolved when steps reference them.

Build the data table

In order to drive multiple test runs with multiple sets of data, MuseIDE needs a data table. These can be created in any spreadsheet program that can output a standard CSV file (comma-separated values). For example:

test1-data-spreadsheet.png

Note that the first row contains column names while the remaining rows contain data. The column names I used match the parameter names expected by the test.

Put the CSV file into the project folder and then restart MuseIDE so that it will recognize the new project resource. The first row of the CSV file is used as column names. The remaining rows are considered data to be used in tests. As rows are used by a parameterized test suite, a set of variables is created from each row. The name of the variable is the column name; the value is the value of that column from the current row.

test1-datatable-resource.png

Create a parameterized test suite

The last step is to create a parameterized test suite. This combines a test with a data table - running the test once with each row of data in the table. Variables injected from a parameterized test suite override the default values for those variables that are configured in the test.

Here I created a parameterized test suite named test1-suite and configured it to run test test1 with values from the searches data table.

test1-paramsuite.png

MuseIDE cannot currently execute a parameterized suite — you must use the Muse command-line tools to run the test (shown below) or run them in your CI server.

muse run test1-suite

Return to Tutorials page