Java Framework Manually Defined

This section covers our Java library which can be directly embedded into any framework coded in the Java language. To integrate data allocations with Java frameworks we expose a Java library which calls the API endpoints mentioned above. This is broken down into the two same functions as before to:

  1. Tag the data allocations against test cases to specify which allocations are required.

  2. Retrieve the allocation results to utilise them as values within a test.

The library and source code can be accessed at the following GitHub repository.

With TestNG you can tag each test with a ‘@DataAllocation’ annotation which is provided by the data allocate java library, shown below:

@DataAllocation(poolName  =  “pool”,  suiteName  =  “suite”,  groups  =  {“testname”})
Public  void  testDefinition()

Here you can specify the data allocation to connect the test with. This corresponds to three parameters:

  • poolName – Name of the allocation pool the tests reside in.

  • suiteName – Name of the test suite the test resides in.

  • groups – The tests to perform allocation on. These are the allocation tests associated with the current test being tagged. Wildcards can be used to match multiple test names. The groups tag also takes a list so multiple test types can be specified.

These three parameters must match the data values specified for each matching test case specified within the appropriate allocation pool within the portal.

Within the test case you can retrieve the results using the ‘dataAllocationEngine.GetDataResult’ function. Here you can specify the pool, suite name, and test name to retrieve the results for. Again, this must match the specifications given in the associated allocation pool within the portal. The DataAllocationResult class shown below contains the functions to retrieve results by the column names, and column indexes as specified in the initial test criteria.

DataAllocationResult  allocResult=  dataAllocationEngine.GetDataResult(“pool”,  “suite”,  “test  name”);

Before the tests are executed in TestNG we have defined a @BeforeSuite function which is executed before all the specified tests are executed. Within this function we collect all @DataAllocate functions tagged against any tests that are about to be executed, then we call the data allocation API to perform the associated executions.

It is more efficient to perform these operations in bulk. Which is why they are collected into one list and then sent for allocation as opposed to directly performing the allocation inside each individual script.

This implementation can be transposed to other testing frameworks (e.g. Nunit, Junit, etc) by replacing the appropriate keywords (@BeforeSuite, and @Test) with their corresponding values. The purpose of this java library is to provide a set of out-the-box methods for enabling you to call the data allocation API within your framework seamlessly.


Java Framework - Test Modeller Code Generation

So far, we have covered creating and tagging the automation code with the associated test data allocations manually. Test Modeller can be used to automatically create this code with the appropriate method calls embedded to execute associated data allocations and consume the resolved results within each associated automation parameter. To do this you must first create a model with both automation and test data allocations overlaid.

Once you have a model with the test data and automation you can click the execute button within the test cases side-bar below.

Once execute has been clicked, the export dialog should be displayed. Here you can specify the server, process, code template, and allocation pool to use. The code template ‘Java Allocation’ contains the appropriate code snippets to construct java allocation code for TestNG (as defined manually above). If the actions below do not appear in your automation server you may need to add data allocation to your server. If your framework is not using our out-the-box TestNG code, you can edit and create custom code templates.

Click the execute button to run the code generator. A first pass is made to perform an initial allocation and create the associated tests within the data catalogue allocation pool selected. After this the associated code is created referencing the created tests within the associated allocation pools selected.

Once the generation is complete a screen will appear with a status of complete and the ability to download a Result.zip file.

Before downloading the created ‘results.zip’ file it is useful to look at the allocation pool you have selected. Here you should see the allocation pool has been populated with the associated test types, along with the initial allocated values.

Within the code folder there is a java file which contains the code definition. Open this file within a text editor to inspect the corresponding java test definition with data allocations generated.

Below is a screen capture of example code file generated. Pay particular attention to the embedded @DataAllocation tag referencing the data pool, test suite, and test cases, along with the appropriate DataAllocationResult objects embedded in the appropriate automation actions by getting the values by column indexes.

TEST DATA AUTOMATION TEST DATA ALLOCATION