Synthetic Data Generation Using Katalon
In the 21st century, data has become an invaluable asset that drives innovation, decision-making, and progress across various domains. Its importance stems from the fact that we are living in a digital age where almost every aspect of our lives generates, consumes, and relies on data.
When it comes to software testing, data plays a crucial role to replicate positive/negative cases and identify corner or edge cases that might remain untested without conducting testing on various data values. Data-Driven testing was born to solve the same problem.
What is data-driven testing (DDT)?
For those of you who are new to the concept of DDT, Data-driven testing (DDT) is a software testing method that stores test data in table or spreadsheet format. Data-driven testing allows testers to input a single test script that can execute tests for all test data from a table and expect the test output in the same table.
There are two major aspects to DDT:
1. Generating Synthetic Data
2. Using the generated data to drive Test Cases.
Katalon for synthetic data generation
For many years Katalon has enabled Data Driven Testing in our platform and complemented this approach through integrations with specialized test data management providers such as GenRocket, Synthesized, and Curiosity Software. We’ve continued to invest further into this important capability with the release of StudioAssist which leverages Generative AI to create fit-for-purpose test data for every test case.
With StudioAssist a next-generation AI-powered coding companion, you can generate code that helps you with synthetic data generation and this could be done just by providing a prompt to StudioAssist in natural language (English).
Read more: Katalon AI-powered testing platform
How to generate synthetic data using StudioAssist?
Step 1: Ensure that StudioAssist is enabled within Katalon Studio 9.0.0, which you can download using the link below.
Step 2: Open any test case, and give a prompt for generating mock/synthetic data, try to write a clear and concise prompt, which specifies your requirements clearly.
Refer to the example prompt below.
Step 3: Select the prompt and right-click, select StudioAssist, and then select “Generate Code.”
Step 4: The code will be generated based on the prompt provided.
In this example, we provided a prompt for generating email IDs and phone numbers but to show an example of customization, we told StudioAssist to generate email IDs with the katalon.com domain and phone numbers that are in the format of Indian phone numbers (Indian numbers start with +91)
Note: The code generated has taken care of customization, you can see the image below, which shows the code generated by StudioAssist. Towards the end, you can see a call being made to a custom keyword, the custom keyword is not generated by StudioAssist but you can ignore it for now and we will talk about it in step 7
Step 5: Make any necessary adjustments, in this case, I have prompted StudioAssist to use the Apache POI library to store the results in an Excel file, also StudioAssist has used Apache common library, hence I would need to import the necessary libraries in the library management section.
More information on Library Management: Here
Step 6: Let's look at the output generated post executing the code developed in Step 4, as expected two fields with the name Email ID and Phone Number have been created and generated data has been pushed in the Excel sheet.
By now you should have a gist of how synthetic data generation would be made easy using Katalon. Also, you can generate data files with thousands of records within a few seconds.
Step 7: If you wish to reduce the manual efforts that go behind creating Data File, you can use the custom keyword below in Katalon Studio to create a Data File in Katalon Studio and link the Excel sheet generated in Step 4 with the Data File. The keyword accepts one String Parameter named as file location, please refer code snippet in step 4 to see how to pass this parameter.
More information on custom keywords: Here
@Keyword
def createTestData(String fileLocation) {
//Linking Excel file that holds Test Data with Katalon Data File
String dataFileName = fileLocation.split("/")[1];
System.out.println(dataFileName);
int index = dataFileName.indexOf(".");
dataFileName = dataFileName.substring(0, index);
System.out.println(dataFileName);
String xmlContent = '<?xml version="1.0" encoding="UTF-8"?>\n' +
'<DataFileEntity>\n' +
' <description></description>\n' +
' <name>'+dataFileName+'</name>\n' +
' <tag></tag>\n' +
' <connectionProperties/>\n' +
' <containsHeaders>true</containsHeaders>\n' +
' <csvSeperator></csvSeperator>\n' +
' <dataSourceUrl>'+fileLocation+'</dataSourceUrl>\n' +
' <driver>ExcelFile</driver>\n' +
' <isInternalPath>true</isInternalPath>\n' +
' <query></query>\n' +
' <secureUserAccount>false</secureUserAccount>\n' +
' <sheetName>Sheet1</sheetName>\n' +
' <usingGlobalDBSetting>false</usingGlobalDBSetting>\n' +
'</DataFileEntity>';
fileLocation = fileLocation.substring(0, fileLocation.indexOf("."));
System.out.println("First String Is: "+fileLocation)
String filePath = fileLocation +".dat";
System.out.println(filePath);
File file = new File(filePath);
file.write(xmlContent, "UTF-8");
}
Step 8: Call to the keyword created in the previous step, needs to be made after the completion of test case execution where we have generated code for creating synthetic data (step 4).
You can refer to the screenshot in step 4 on how and when the call is made to the custom keyword.
The final result should look something like shown in the below screenshot.
Conclusion
Today's data-driven testing is an effective way to ensure that software tests are comprehensive and efficient. With the help of Katalon StudioAssist, it's never been easier to generate synthetic data for data-driven testing and carry out tests quickly and without any hassle. It's clear that Katalon offers a convenient and streamlined solution for automation testing in the modern world.
We hope you are excited about this feature and this guide is helpful to apply it to your current testing projects. Stay tuned for more.