Running MSbuild using GXtest Target

Unofficial Content

In order to create msbuild tasks easier, you will find a GXtest.msbuild file in your GeneXus IDE installation folder. This file has already defined dependencies and previous tasks that are mandatory before running tests, such as: open KB, select Environment, create test references, build the test runner, etc. 

For example, this is how “RunAllTests” target (which includes RunTests task) looks like in the GXtest.msbuild file:

<Target Name="RunAllTests">
  <OpenKnowledgeBase Directory="$(KBPath)"/>
    <SetActiveEnvironment EnvironmentName="$(EnvironmentName)"/>
    <UpdateTestRefs Type="$(TestType)"/>
    <BuildOne BuildCalled="true" ObjectName="$(RunnerName)"/>
    <RunTests Type="$(TestType)" DetailedResults="true"/
  <CloseKnowledgeBase/>
</Target>

And this is how “RunTestsList” target (which includes RunTestsList task) looks like:

<Target Name="RunTestsList">
  <OpenKnowledgeBase Directory="$(KBPath)"/>
    <SetActiveEnvironment EnvironmentName="$(EnvironmentName)"/>
    <UpdateTestRefs ExecutionDataFilePath="$(pathToJSON)"/>
    <BuildOne BuildCalled="true" ObjectName="Runner"/>
    <RunTestsList ExecutionDataFilePath="$(pathToJSON)"/>
  <CloseKnowledgeBase/>
</Target>

The next examples will show how to run different test cases in a CI / CD scheme.

 

Example 1: Running all Unit tests

The following command line example runs all unit tests in the KB:

MSBuild.exe /t:RunAllTests /p:KBPath="C:\Models\KbTests" /p:EnvironmentName="CSharpWeb" /p:TestType="Unit" PATH_TO_YOUR\GXtest.msbuild

Example 2: Running a suite of UI tests using Google Chrome

The following command line example runs 3 UI tests (TestName1, TestName2 and TestName3) using Google Chrome driver:

MSBuild.exe /t:RunTestsList /p:KBPath="C:\Models\KbTests" /p:EnvironmentName="CSharpWeb" /p:ExecutionDataFilePath="PATH_TO_YOUR\test_suite.json"  PATH_TO_YOUR\GXtest.msbuild

In this case, the test_suite.json needs to looks like:

{"UI":{"Settings":{"BaseURL":"http://localhost/TestEnvironment/","Browser":"Chrome"},"Tests":["TestName1","TestName2","TestName3"]}}

Example 3: Running Unit and UI test combined

Running both test type is not something common, but you can do it using the RunTestsList task.

MSBuild.exe /t:RunTestsList /p:KBPath="C:\Models\KbTests" /p:EnvironmentName="CSharpWeb" /p:ExecutionDataFilePath="PATH_TO_YOUR\test_suite.json"  PATH_TO_YOUR\GXtest.msbuild

In this case, the test_suite.json needs to looks like:

{"UI":{"Settings":{"BaseURL":"http://localhost/TestEnvironment/","Browser":"Edge"},"Tests":["UITest1"]},"Unit":{"Tests":["Proc1UnitTest", "Proc2UnitTest", "DataProvider1UnitTest"]}}