Running MSbuild using GXtest Target

Official 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 the “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)" ServerUserName="local\Admin" ServerPassword="password"/>
    <BuildOne BuildCalled="true" ObjectName="$(RunnerName)"/>
    <RunTests Type="$(TestType)" DetailedResults="true" ServerUserName="local\Admin" ServerPassword="password"/>
  <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)" ServerUserName="gxtechnical\username" ServerPassword="password"/>
    <BuildOne BuildCalled="true" ObjectName="Runner"/>
    <RunTestsList ExecutionDataFilePath="$(pathToJSON)" ServerUserName="gxtechnical\username" ServerPassword="password"/>
  <CloseKnowledgeBase/>
</Target>

*Note: you have to set the server user (local or gxtechnical) and password to run the tasks. 

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 look like:

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

Example 3: Running Unit and UI test combined

Running both test types 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"]}}

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