CI / CD integration for Unit Tests

Official Content
This documentation is valid for:

As discussed in the Typical GeneXus development cycle for Agile, the software industry has evolved to enable a set of automation to boost quality and adopting DevOps practices. Continuous integration is a fundamental step to start working in a proper way with GXserver and GXtest.

Continuous integration means that every time a developer makes a change in a centralized repository in GXserver KB, that code will trigger some automation to check that recent changes can successfully build a new version without conflicts with other developments. Also, it will check that there are no missing references to be committed and that the build succeeds in a totally different environment than it was developed. With this step in your process, you will be avoiding the typical dev phase like “it works/builds on my machine”. Theoretically, CI means to integrate every time a developer makes a commit, but sometimes in your methodology, you want to do this less often but still getting often (maybe daily) feedback regarding your app status. In other words, that is continuously integrated.

CI tools are usually agnostic, and you can integrate GeneXus with any CI tools using msbuild.exe on windows platforms. As an example, we will be showing some cases using Jenkins CI.

In the same way that you will use GeneXus Tasks such as OpenKB, BuildAll, RebuildAll, etc. for handling Knowledge Base tasks and Team Development Tasks for handling GXServer, to run Unit tests you will need to call some extra task/step. You can find proper documentation of these tasks here.

How to Run All your Unit Tests in your KB

GXtest.msbuild: Let's assume that this is the filename of the MSBuild File that you are building to run Unit Tests.

In the beginning, you will need to import two MSBuild projects that contain predefined tasks that you are going to use on your file. Those projects are: GeneXus.Tasks.targets and GXtest.targets.

The following is an example of the MSBuild file:

<Project xmlns="">    
  <Import Project="$(GX_PROGRAM_DIR)\GeneXus.Tasks.targets"/>    
  <Import Project="$(GX_PROGRAM_DIR)\GXtest.targets"/>

  <Target Name="RunAllTests">
    <OpenKnowledgeBase Directory="$(KBPath)"/>
    <SetActiveEnvironment EnvironmentName="$(EnvironmentName)"/>
    <UpdateTestRefs Type="$(TestType)" ServerUserName="$(GXUser)" ServerPassword="$(GXPass)"/>
    <BuildOne BuildCalled="true" ObjectName="Runner"/>
    <RunTests Type="$(TestType)" ServerUserName="$(GXUser)" ServerPassword="$(GXPass)"/>

Having this file configured properly, you can launch all unit tests using this command line: 

MSBuild.exe /t:RunAllTests /p:KBPath="C:\Models\KbTests" /p:EnvironmentName="CSharpWeb" /p:TestType="Unit" /p:GXUser="local\admin" /p:GXPass="password" $env:GX_PROGRAM_DIR"\GXtest.msbuild"

How to Run a Test List (suite) of your KB

As well as the task Run All Tests, you will need to configure an MSBuild file as is showed below:

<Project xmlns="">    
<Import Project=".\GeneXus.Tasks.targets"/>    
<Import Project=".\GXtest.targets"/>

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

Having this file configured properly, you can run a specific unit tests list using this command line:

MSBuild.exe /t:RunTestsList 
/p:GXUser="local\admin" /p:GXPass="password"


See MSbuild examples