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)" Browser="$(Browser)" BaseURL="$(BaseURL)" FileUploadBasePath="$(FileUploadBasePath)" DetailedResults="true" ServerUserName="local\Admin" ServerPassword="password"/>
<JUnitExportTests JUnitTestFilePath="$(JUnitTestFilePath)" >
<Output TaskParameter="JUnitTestFilePath" PropertyName="JUnitTestFilePathOutput" />
</JUnitExportTests>
<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"/>
<JUnitExportTests JUnitTestFilePath="$(JUnitTestFilePath)">
<Output TaskParameter="JUnitTestFilePath" PropertyName="JUnitTestFilePathOutput" />
</JUnitExportTests>
<CloseKnowledgeBase/>
</Target>
*Note: you have to set the server user (local or gxtechnical) and password to run the tasks.
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" /p:GXServerUser="local\admin" /p:GXServerPass="password" PATH_TO_YOUR\GXtest.msbuild
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" /p:GXServerUser="local\admin" /p:GXServerPass="password" 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","MyModule.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" /p:GXServerUser="local\admin" /p:GXServerPass="password" 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", "ModuleX.DataProvider1UnitTest"]}}
|