BreadcrumbHomeResourcesBlog BlazeMeter Mock Services and Test Data | How To Understand March 28, 2022 BlazeMeter Mock Services and Test Data | How to UnderstandTest Data ManagementService VirtualizationBy Surya SuravarapuTo meet the customer needs in the digital age, it is essential for companies to innovate faster and respond quickly to customer needs. Having a successful DevOps implementation helps companies achieve this elusive goal. Continuous Testing, which is the process of embedding testing as an ongoing aspect of every activity in the software delivery life cycle, is a key factor for DevOps success. BlazeMeter provides a single shift left continuous testing platform which lets us perform functional testing, performance testing and API monitoring. Mock services and test data are important for high quality testing and to help eliminate dependencies. Table of ContentsDefining service data in mock servicesUsing Synthetic Data parametersUser definition of custom data field – radiusUsing Existing Data SourcesCreating and editing a new data tableImporting existing CSV fileParameterizing request parametersParameterizing response dataMock service data settingsSharing Test DataUsing Shared FoldersSaving to WorkspaceExporting to other workspacesUsing the shared dataLoading data entities saved to the workspaceLinking test data defined in the mock serviceSummaryTable of Contents1 - Defining service data in mock services2 - Using Synthetic Data parameters3 - User definition of custom data field – radius4 - Using Existing Data Sources5 - Creating and editing a new data table6 - Importing existing CSV file7 - Parameterizing request parameters8 - Parameterizing response data9 - Mock service data settings10 - Sharing Test Data11 - Using Shared Folders12 - Saving to Workspace13 - Exporting to other workspaces14 - Using the shared data15 - Loading data entities saved to the workspace16 - Linking test data defined in the mock service17 - SummaryMock services help simulate unavailable and constrained systems and achieve high availability to shift left and to test completely. Every test needs test data. Having a comprehensive test data ensures high quality testing with good coverage. The following diagram shows how test data and mock services are the foundation for your testing activities.Let’s talk about how test data and mock services work together. BlazeMeter provides an out of the box ability to integrate test data into mock services. In addition, BlazeMeter also allows the test data to be synchronized across the tests and mock services which ensures data consistency and provides a complete testing experience. Having high quality test data is essential for mock services to service the different testing needs. A combination of on-demand test data generation (using synthetic data) and existing test data (through CSV files and TDM integration) will help generate comprehensive test data to be used in the mock services. Mock services are comprised of transactions which are combinations of request and response pairs associated with a given service. These transactions can be linked to service data entities which contain the different sources of test data as shown below. Back to topDefining service data in mock services The data parameters from these service data entities can be used to parameterize the requests and responses to use the test data and provide dynamic responses based on the incoming requests. The test data can either be generated using synthetic data generation or existing test data or a combination of both. Since mock services are not stateful, the test data does not get updated or changed when the services handle the requests. This can help eliminate data burnout especially while performing update operations. Back to topUsing Synthetic Data parametersThis type of data source helps generate test data dynamically using examples such as sample US addresses or by user definition of the test data using in-built functions. US Address – Example data definition Back to topUser definition of custom data field – radius Once the data source has been defined, we can preview the data by clicking on data settings as shown below. Updating the value under ‘Defined Number of Rows’ would generate the desired numbers of rows of data using the seed data for the example fields chosen. Defining rows of data using Synthethic data definitions Back to topUsing Existing Data SourcesThis involves loading data from CSV files that can be uploaded or from shared folders in the workspace. In addition, customers who have the Test Data Manager product from Broadcom can take advantage of the integration which lets them search for data that matches specific requirements across distributed data sources. Loading data from CSV involves either creation of new CSV file (data table) or importing existing CSV file. Creating a new data table provides a tabular view where individual cells can be edited, and new rows / columns can be added to create the data table as shown below. Back to topCreating and editing a new data table Importing existing CSV file will create test data from the CSV data as shown below. There are various options to control the number of rows of test data used which are described at the link. Using these options, you can determine the number of rows of data from all applicable files that will be used, skipped or looped, respectively. For example, instead of using ‘All Rows’, if we specify the ‘Defined Number of Rows’, depending on the size of the file, it will either skip rows (if the defined number is smaller than the number of rows in the CSV file) or loop rows (if the defined number is larger than the number of rows in the CSV file). Back to topImporting existing CSV file Once the data source has been defined, the next step is to parameterize the request and response data that needs to be substituted as shown below. We can copy the test data parameter value names by clicking the copy button and then paste them in place of the hardcoded values in the request and response. Back to topParameterizing request parameters Back to topParameterizing response data After the transaction is updated and service is deployed using the transactions, the request argument (zipCode) of incoming request will be used to look up the data row from the data set and the response parameters will be substituted with the row data. Back to topMock service data settings Mock service response using test data Back to topSharing Test DataThere are multiple ways in which test data can be shared by users within the workspace across mock services, GUI Functional and Performance tests which are as given below. Back to topUsing Shared FoldersData entity can also be created from existing data sets (CSV files) in shared folders. The CSV files in the shared folders can be used by users across the workspace for GUI Functional, Performance Tests and Mock Services. In the attach CSV files from Shared Folders window, new folders / CSV files can be added or deleted as needed. Attaching files from shared folders In addition to creating a new data entity, users can also load a data entity that has been saved to the workspace or import a data entity from exported file. Back to topSaving to WorkspaceData Entity menu provides option to Save the data entity to the workspace. Once this is done, the test data can be shared by users within the workspace and can be used across performance tests, functional tests, and mock services. After we have created test data for a mock service, optionally, we can save the data entities to share them with users of the Workspace. We can open a saved test data entity in any test with test data support in the same workspace. Saving data entity to the workspace Back to topExporting to other workspacesExporting the data entity using the ‘Export to File’ option generates a zip file which can then be imported into other workspaces to add the data entity. CSV Files and files from shared folders are not included in the saved data entity. Back to topUsing the shared dataTest data shared can be used across other capabilities in Blazemeter such as performance tests and functional tests as shown below. Back to topLoading data entities saved to the workspace There is the option of loading Data entities shared in the workspace or the option of loading data entities exported from other workspaces. This will ensure the same test data is used across the tests and mock services. As shown below, when we added the mock service to the test, it also loaded the service data which gives the option to use the same test data for the test (performance test in this case). This will ensure the data is consistent across the tests and the corresponding mock services that support the tests. Back to topLinking test data defined in the mock service In addition the above, users have the option of using the BlazeMeter integration of Test Data Manager (TDM) product to consume the tests data. Back to topSummaryTest data is a new and key functionality in BlazeMeter which helps users quickly provide data for use in mock services instead of hardcoding data. The same test data can be used across the other capabilities like performance and functional tests to ensure data consistency. This will play an important role in helping customers improve the effectiveness of their continuous testing practices and to achieve their DevOps and business goals. START TESTING NOW Related ResourcesTest Data Setup: How to Use BlazeMeter to Get Reliable DataHow to use Mock Services in BlazemeterBack to top
Surya Suravarapu Senior Engineering Services Architect, CA Technologies Surya Suravarapu has over 13 years of experience supporting customers in Development and QA areas. He has been part of the customer facing SWAT team with expertise in DevOps products for the last 4 years at CA Technologies, a Broadcom company.