概要
UEでは自動テストのフレームワークがいくつか用意されています。
今回はGauntletと呼ばれるフレームワークについて説明したいと思います。
基本的な自動テスト環境のセットアップはこちらの記事を参照してください。
この中でもプラグインの設定でGauntletを有効にしておく必要があるので注意が必要です。
動作環境
UnrealEngine 5.4.4
プロジェクトに追加
エンジン側のGauntletのサンプルは実行はできましたが、プロジェクト側に新規で追加する方法が分かりませんでした。
プロジェクト側で新規にGauntletを追加する方法でEpicのページを参考に進めてみますが、分かりづらいのと、そのままでは対応できない部分があったのでそのあたりも含めて説明していきたいと思います。
基本的にはGauntlet用のC#のプロジェクトを追加する必要があります。
プロジェクトのGames側のフォルダで右クリックし、追加を選択します。
新しいプロジェクトの追加でクラスライブラリを選択します。
※クラスライブラリ(.NET framework)ではないので注意
以下の設定でプロジェクトを作成します。
プロジェクト名:{project}.Automation
場所:{project}\Build\Scripts\
※プロジェクト名は推奨の命名規則
※これで作成すると\Build\Scripts\以下に{project}.Automationのフォルダも作成されますが、今回はこのままでいきます
追加情報でフレームワークは.NET 6.0を選択します。
これで作成を行います。
作成を行うとClass1.csというC#のファイルが追加されているので{project}.csに変更します。
追加したプロジェクトを右クリックしてプロパティを選択します。
出力の項目の基本出力パスがbin\になっていることを確認します。
ビルドの構成マネージャーを選択します。
追加したプロジェクトの構成のドロップダウンから<編集>を選択します。
Releaseを選択して名前の変更でDevelopmentに変更します。
プロジェクトのコンテキストをDevelopmentに変更しておきます。
- AutomationScripts.Automation
- AutomationUtils.Automation
- EpicGames.Build
- EpicGames.Core
- Gauntlet.Automation
Gauntletの自動テストのソースを追加してみます。
Epicのページを元に最小限の呼び出しを記述してみます。
using AutomationTool; namespace TestProject.Automation { // BuildCommand はすべてのコマンドの基本クラスです。 public class SampleCommand : BuildCommand { public override void ExecuteBuild() { LogInformation("Gauntlet TestProject.Automation : SampleCommand.ExecuteBuild()"); } } }
LogInformationが非推奨となっているので、これを解消する必要があります。
右クリックのNuGetの管理を開きます。
Microsoft.CSharpをインストールします。
using AutomationTool; using Microsoft.Extensions.Logging; namespace TestProject.Automation { // BuildCommand はすべてのコマンドの基本クラスです。 public class SampleCommand : BuildCommand { public override void ExecuteBuild() { Logger.LogInformation("Gauntlet TestProject.Automation : SampleCommand.ExecuteBuild()"); } } }
コマンドラインから実行します。
この際、-scriptdirでプロジェクトのディレクトリを指定する必要があるので注意が必要です。
RunUAT.bat SampleCommand -scriptdir=d:\project\TestProject\Build\Scripts\
追加したログが出力されていることが確認できます。
Running AutomationTool... Using bundled DotNet SDK version: 6.0.302 Starting AutomationTool... Parsing command line: SampleCommand -scriptdir=d:\project\TestProject\Build\Scripts\ Initializing script modules... Building 32 projects (see Log 'Engine/Programs/AutomationTool/Saved/Logs/Log.txt' for more details) Restore... Build... Build projects time: 38.07 s Total script module initialization time: 42.14 s. Executing commands... Gauntlet TestProject.Automation : SampleCommand.ExecuteBuild() BUILD SUCCESSFUL AutomationTool executed for 0h 0m 44s AutomationTool exiting with ExitCode=0 (Success)
これでGautletの自動テストの処理が呼び出せるようになりました。
後はテストの処理などを実装して呼び出しを行うことでGauntletの環境でも自動テストが行えるようになると思います。