Querying Data or Metadata

Table of Contents

Within a testcase- or testsuite-script you can query data from an external datasource. This can either be actual data or metadata as well. This makes you capable of using this data to control the flow of the testcase.

For example you could query a list of sales-territories and run the testcase once for each of them.

Or you may query a list of tables with a specific name (e.g. Dim…) from your data warehouse to run a testcase for each of them.

We added some convenience-functions to the BiG EVAL scripting infastructure to make this more efficient.

Please note that each of these functions takes the name of the datasource where we will fire the query against, as a parameter.

Querying a Scalar Value from a Datasource

Use the following line of code to query a single value (scalar value) from a specific datasource.

var maxAmount = QueryValue("AW ERP", "SELECT MAX(Amount) FROM Sales");

The first parameter of this function is the name of the datasource.

The second parameter is the Query that gets run on the datasource. Use the syntax of the actual technology of the datasource.

The function returns the scalar value. In the example, we store the value in the variable maxAmount to use it later on.

Querying a List of Values from a Datasource

Use the following line of code to query a list of values from a specific datasource.

var listOfCustomerIDs = QueryList("AW ERP", "SELECT CustomerID FROM Customers");

The first parameter of this function is the name of the datasource.

The second parameter is the Query that gets run on the datasource. Use the syntax of the actual technology of the datasource.

The function returns an IList<Object>. This means that it returns a list of values as the type they are returned from the database. It these are numbers, it gets a list of numbers. If the values are characters, it returns a list of strings. And so on.

The following example shows how to use that list to iterate over it and run the testcase for each value in the list.

foreach(var customerID in listOfCustomerIDs)  
{  
    // Set Parameter-value  
    SetParameter("CustomerID", customerID);  

    // Execute test  
    await ExecuteAsync();  
}

Querying a Table from a Datasource

Use the following line of code to query a table from a specific datasource.

var customerData = QueryTable("AW ERP", "SELECT * FROM Customers");  

The first parameter of this function is the name of the datasource.

The second parameter is the Query that gets run on the datasource. Use the syntax of the actual technology of the datasource.

The function returns a DataTable object (see System.Data.DataTable).

The following example shows how to use that DataTable to iterate over it and run the testcase for each row inside.

foreach(DataRow customer in customerData.Rows)  
{  
    // Read customer properties 
    var customerID = customer["CustomerID"]; 
    var customerName = customer["Name"]; 

    // Set Parameter-value 
    SetParameter("CustomerID", customerID); 

    // Set the comment of the test-execution 
    SetComment($"Executing Test for Customer '{customerName}' ({customerID})");

    // Execute test  
    await ExecuteAsync();  
}