MSbuild Tasks for Running Tests

Official Content

Running test cases in a batch mode is easy using MSBuild tasks. There are 2 specific tasks* used for this purpose: RunTests and RunTestsList.

* Note: Instead of using these tasks isolated, we recommend to start using the GXtest.msbuild file that should be present on your GeneXus installation root folder, and modify it at your own needs. You will see an example in the next article. 

1 - UpdateTestRefs (MSBuild Task)

This task must be used before executing RunTests, RunTestsList and RecordMockingData tasks and tests to run must exist at the moment this task is used. After this task, Runner procedure must be built (see examples below).

Parameters:
Type: {All, Unit, Web, UI, SD} 
Specifies the type of test to run. Set
All: to run all Unit tests first, then web UI tests, and at last all SD UI tests. Default value.
Unit: to run all Unit tests.
Web: to run all web UI tests.
SD: to run all SD tests.
UI: to  run all web and SD UI tests.

TestName: string
Specifies the name of the test to run. 

ExecutionDataFilePath: string
An absolute path to the JSON file containing test cases and options.

ServerUserName: string
Specifies the server user name (local or gxtechnical)

ServerPasswordstring
Specifies the server password.

Examples of use in an MSBuild file:

<UpdateTestRefs Type="All" ServerUserName="gxtechnical\username" ServerPassword="password"/>
<BuildOne BuildCalled="true" ObjectName="Runner"/>
<RunTests Type="All" DetailedResults="true" ServerUserName="gxtechnical\username" ServerPassword="password"/>
<UpdateTestRefs TestName="testExample" ServerUserName="local\admin" ServerPassword="password"/>
<BuildOne BuildCalled="true" ObjectName="Runner"/>
<RecordMockingData TestName="testExample" ServerUserName="local\admin" ServerPassword="password">
<UpdateTestRefs ExecutionDataFilePath="MyPath/ExecData.json" DetailedResults=”true” ServerUserName="gxtechnical\username" ServerPassword="password"/>
<BuildOne BuildCalled="true" ObjectName="Runner"/>
<RunTestsList ExecutionDataFilePath="MyPath/ExecData.json" DetailedResults=”true” ServerUserName="gxtechnical\username" ServerPassword="password"/>

2 - RunTests (MSBuild Task)

This task runs all the test cases (Unit, UI or both) in a specific Knowledge Base. 
The sequence/order of execution is alphabetically grouped by folders.

Type: {All, Unit, Web, UI, SD} 
Specifies the type of test to run. Set
All: to run all Unit tests first, then web UI tests, and at last all SD UI tests. Default value.
Unit: to run all Unit tests.
Web: to run all web UI tests.
SD: to run all SD tests.
UI: to  run all web and SD UI tests.

DetailedResults (optional): bool
A boolean parameter to set verbosity. 
If true, detailed results will be displayed on the console output.
If false, only a summary is shown.

ServerUserName: string
Specifies the server user name (local or gxtechnical)

ServerPasswordstring
Specifies the server password.

AllowFailedTestsboolean
true: task will success even if exists a test that failed.
false: If there is any failed test, this task is set as failed and pipeline fails.

Examples of use in an MSBuild file:

<RunTests Type="All" ServerUserName="gxtechnical\username" ServerPassword="password"/>
<RunTests Type="Unit" DetailedResults="true" ServerUserName="local\admin" ServerPassword="password"/>
<RunTests Type="UI" ServerUserName="gxtechnical\username" ServerPassword="password" AllowFailedTests="true"/>

3 - RunTestsList (MSBuild Task)

This task runs a list of test cases defined by you (in a JSON file). The sequence/order of execution will depend on the ordered written in that file. You can see JSON file examples below this section.

Parameters:
ExecutionDataFilePath: string
An absolute path to the JSON file containing test cases and options.

DetailedResults (optional): bool
A boolean parameter to set verbosity. 
If true, detailed results will be displayed on the console output.
If false, only a summary is shown.

ServerUserName: string
Specifies the server user name (local or gxtechnical)

ServerPasswordstring
Specifies the server password.

AllowFailedTestsboolean
true: task will success even if exists a test that failed.
false: If there is any failed test, this task is set as failed and pipeline fails.

Example of use in a msbuild file:

<RunTestsList ExecutionDataFilePath="MyPath/ExecData.json" DetailedResults=”true” ServerUserName="gxtechnical\username" ServerPassword="password"/>

4 - RecordMockingData(MSBuild task)

Mocking works by recording data (SQLs / results) used for a test. This information is stored (as mocking data) and will be used in all future executions of the test in different environments. 

Parameters:
TestName: string
Specifies the name of the test to run. 

MockDataFilePath (output): string
The absolute path where the mocking data file was saved.

ServerUserName: string
Specifies the server user name (local or gxtechnical)

ServerPasswordstring
Specifies the server password.

Examples of use in a msbuild file:

<RecordMockingData TestName="testExample"  ServerUserName="gxtechnical\username" ServerPassword="password">
    <Output TaskParameter="MockDataFilePath" PropertyName="MockPath"/>
</RecordMockingData>
<RecordMockingData TestName="testExample" ServerUserName="local\admin" ServerPassword="password">
    <Output TaskParameter="MockDataFilePath" PropertyName="MockPath"/>
</RecordMockingData>

5 - JUnitExportTests(MSBuild task)

Converts the last execution test results to junit format.

Parameters:
JUnitTestFilePath (input/output): string
An absolute directory path where the junit file will be saved / As output, contains the junit file's absolute path.

ServerUserName: string
Specifies the server user name (local or gxtechnical).

ServerPasswordstring
Specifies the server password.

Examples of use in a msbuild file:

<JUnitExportTests JUnitTestFilePath="C:/path" ServerUserName="gxtechnical\username" ServerPassword="password">  
    <Output TaskParameter="JUnitTestFilePath" PropertyName="JUnitTestFilePathOutput"/>
</JUnitExportTests>
<JUnitExportTests JUnitTestFilePath="C:/path" ServerUserName="local\admin" ServerPassword="password"> 
    <Output TaskParameter="JUnitTestFilePath" PropertyName="JUnitTestFilePathOutput"/>
</JUnitExportTests>


Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.