Running MSbuild using GXtest Target

Official Content
This documentation is valid for:

In order to create MSBuild tasks easier, you will find a GXtest.msbuild file in your GeneXus IDE installation folder. This file has predefined dependencies and previous tasks that are mandatory before running tests, such as opening a KB, selecting an environment, updating test references, building the tests runner, etc. 

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

<Target Name="RunTests">
    <OpenKnowledgeBase Directory="$(KBPath)"/>
    <SetActiveEnvironment EnvironmentName="$(EnvironmentName)"/>
      <UnitTests Include="$(UnitTests)"/>
      <WebTests Include="$(WebTests)"/>
      <Suites Include="$(Suites)"/>
    <RunTests Type="$(TestType)" TestObjects="$(TestObjects);$(UnitTests);$(WebTests);$(Suites)"
              Browser="$(Browser)" BaseURL="$(BaseURL)" FileUploadBasePath="$(FileUploadBasePath)" 
              ScreenshotMode="$(ScreenshotMode)" HtmlMode="$(HtmlMode)" Arguments="$(Arguments)"
              ServerUserName="$(GXServerUser)" ServerPassword="$(GXServerPass)" 
              AllowFailedTests="$(AllowFailedTests)" ResultsFile="$(ResultsFile)">
      <Output TaskParameter="ExecutedCount" PropertyName="ExecutedCount"/>
      <Output TaskParameter="SuccessCount" PropertyName="SuccessCount"/>
      <Output TaskParameter="ErrorCount" PropertyName="ErrorCount"/>
      <Output TaskParameter="WarningCount" PropertyName="WarningCount"/>
      <Output TaskParameter="SkippedCount" PropertyName="SkippedCount"/>
      <Output TaskParameter="ResultsFile" PropertyName="ResultsFile"/>
      <!-- Type can be 'UI' to run only UI tests, 'Unit' to run only unit tests or 'All' to run both.  -->
    <JUnitExportTests SourceResultsFile="$(ResultsFile)" JUnitTestFilePath="$(JUnitTestFilePath)" >
      <Output TaskParameter="JUnitTestFilePath" PropertyName="JUnitTestFilePathOutput" />
    <ExportResultsToAllure TargetDir="$(AllureResultsPath)" Properties="KB=$(KBPath);Environment=$(EnvironmentName);$(TestingEnvironment)">
      <Output TaskParameter="OutputFiles" PropertyName="OutputFiles" />      

*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:RunTests /p:KBPath="C:\Models\KbTests" /p:EnvironmentName="CSharpWeb" /p:TestType="Unit"  /p:GXServerUser="local\admin" /p:GXServerPass="password"  PATH_TO_YOUR\GXtest.msbuild 

Example 2: Running web UI tests using Google Chrome browser headless

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

MSBuild.exe /t:RunTests /p:KBPath="C:\Models\KbTests" /p:EnvironmentName="CSharpWeb" /p:TestObjects="TestName1;TestName2;TestName3" /p:Browser="Chrome"  /p:Arguments="--headless" /p:GXServerUser="local\admin" /p:GXServerPass="password" PATH_TO_YOUR\GXtest.msbuild

Example 3: Running Test Suites

You can run any type of test object by passing it as the TestObjects parameter, e.g. a unit test, a web UI test, and a test suite.

MSBuild.exe /t:RunTests /p:KBPath="C:\Models\KbTests" /p:EnvironmentName="CSharpWeb" /p:TestObjects="AUnitTest;AWebUITest;ATestSuite"  /p:GXServerUser="local\admin" /p:GXServerPass="password"  PATH_TO_YOUR\GXtest.msbuild

Note: for any command execution you could override the properties set for a KB/environment, such as Browser, Base URL, Screenshot and HTML saving modes, Arguments, etc.