GeneXus IDE のインストールフォルダには、MSBuild タスクの作成を容易にする
GXtest.msbuild ファイルがあります。このファイルには、依存関係と、ナレッジベースを開く、環境を選択する、テストの参照を更新する、テストランナーをビルドするといった、テストを実行する前に行う必要のあるタスクが事前に定義されています。
たとえば、GXtest.msbuild ファイルでは「
RunTests」のターゲット (
RunTests タスクを含む) は次のようになっています:
<Target Name="RunTests">
<OpenKnowledgeBase Directory="$(KBPath)"/>
<SetActiveEnvironment EnvironmentName="$(EnvironmentName)"/>
<ItemGroup>
<UnitTests Include="$(UnitTests)"/>
<WebTests Include="$(WebTests)"/>
<Suites Include="$(Suites)"/>
</ItemGroup>
<RunTests Type="$(TestType)" TestObjects="$(TestObjects);$(UnitTests);$(WebTests);$(Suites)"
Browser="$(Browser)" BaseURL="$(BaseURL)" FileUploadBasePath="$(FileUploadBasePath)"
ScreenshotMode="$(ScreenshotMode)" HtmlMode="$(HtmlMode)" Arguments="$(Arguments)"
DetailedResults="$(DetailedResults)"
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. -->
</RunTests>
<JUnitExportTests SourceResultsFile="$(ResultsFile)" JUnitTestFilePath="$(JUnitTestFilePath)" >
<Output TaskParameter="JUnitTestFilePath" PropertyName="JUnitTestFilePathOutput" />
</JUnitExportTests>
<ExportResultsToAllure TargetDir="$(AllureResultsPath)" Properties="KB=$(KBPath);Environment=$(EnvironmentName);$(TestingEnvironment)">
<Output TaskParameter="OutputFiles" PropertyName="OutputFiles" />
</ExportResultsToAllure>
<CloseKnowledgeBase/>
</Target>
*注: タスクを実行するには、サーバーのユーザー名 (local または gxtechnical) とパスワードを設定する必要があります。
ナレッジベース内のすべてのユニットテストを実行する場合のコマンドラインの例を示します:
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
Google Chrome のヘッドレスモードを使用して、3 つの Web UI テスト (
TestName1、TestName2、TestName3) を実行する場合のコマンドラインの例を示します:
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
TestObjects パラメーターとしてテストオブジェクトを渡すことで、ユニットテスト、Web UI テスト、テストスイートなど任意のタイプのテストを実行できます。
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
注: コマンドを実行すると、ナレッジベース/環境に設定されたプロパティが上書きされる可能性があります。たとえば、ブラウザー、ベース URL、スクリーンショットと HTML の保存モード、引数などが上書きされる可能性があります。