Skip to content

Commit

Permalink
Merge pull request #98 from nowsprinting/feature/junit_reporter
Browse files Browse the repository at this point in the history
Add JUnitXmlReporter
  • Loading branch information
asurato authored Nov 8, 2024
2 parents 2a6a4f8 + ff6d24d commit c675058
Show file tree
Hide file tree
Showing 17 changed files with 685 additions and 262 deletions.
19 changes: 11 additions & 8 deletions Editor/Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ msgstr "タイムスケール"
msgid "Time.timeScale on running Autopilot"
msgstr "Time.timeScaleを指定します"

# junitReportPath
msgid "JUnit Report Path"
msgstr "JUnitレポート出力パス"

# junitReportPath tooltip
msgid "JUnit report output path"
msgstr "JUnit形式のレポートファイル出力パス(省略時は出力されない)"

# logger
msgid "Loggers"
msgstr "Loggers"
Expand Down Expand Up @@ -471,6 +463,17 @@ msgid "Reporters"
msgstr "Reporters"


#: Editor/UI/Reporters/JUnitXmlReporterEditor.cs

# outputPath
msgid "Output File Path"
msgstr "出力ファイルパス"

# outputPath tooltip
msgid "Relative path from the project root directory. When run on player, it will be the Application.persistentDataPath."
msgstr "プロジェクトルートからの相対パスを指定します。プレイヤー実行の際は Application.persistentDataPath が起点となります"


#: Editor/UI/Reporters/SlackReporterEditor.cs

# slackToken
Expand Down
56 changes: 56 additions & 0 deletions Editor/UI/Reporters/JUnitXmlReporterEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// This software is released under the MIT License.

using DeNA.Anjin.Reporters;
using UnityEditor;
using UnityEngine;

namespace DeNA.Anjin.Editor.UI.Reporters
{
/// <summary>
/// Editor for <c cref="JUnitXmlReporter"/>.
/// </summary>
[CustomEditor(typeof(JUnitXmlReporter))]
public class JUnitXmlReporterEditor : UnityEditor.Editor
{
private const float SpacerPixels = 10f;

// @formatter:off
private static readonly string s_description = L10n.Tr("Description");
private static readonly string s_descriptionTooltip = L10n.Tr("Description about this Reporter instance");
private GUIContent _descriptionLabel;
private SerializedProperty _descriptionProp;

private static readonly string s_outputPath = L10n.Tr("Output File Path");
private static readonly string s_outputPathTooltip = L10n.Tr("Relative path from the project root directory. When run on player, it will be the Application.persistentDataPath.");
private GUIContent _outputPathLabel;
private SerializedProperty _outputPathProp;
// @formatter:on

private void OnEnable()
{
Initialize();
}

private void Initialize()
{
_descriptionProp = serializedObject.FindProperty(nameof(JUnitXmlReporter.description));
_descriptionLabel = new GUIContent(s_description, s_descriptionTooltip);

_outputPathProp = serializedObject.FindProperty(nameof(JUnitXmlReporter.outputPath));
_outputPathLabel = new GUIContent(s_outputPath, s_outputPathTooltip);
}

public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(_descriptionProp, _descriptionLabel);
GUILayout.Space(SpacerPixels);

EditorGUILayout.PropertyField(_outputPathProp, _outputPathLabel);

serializedObject.ApplyModifiedProperties();
}
}
}
3 changes: 3 additions & 0 deletions Editor/UI/Reporters/JUnitXmlReporterEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Editor/UI/Settings/AutopilotSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public class AutopilotSettingsEditor : UnityEditor.Editor
private static readonly string s_timeScale = L10n.Tr("Time Scale");
private static readonly string s_timeScaleTooltip = L10n.Tr("Time.timeScale on running Autopilot");

private static readonly string s_junitReportPath = L10n.Tr("JUnit Report Path");
private static readonly string s_junitReportPathTooltip = L10n.Tr("JUnit report output path");

private static readonly string s_loggers = L10n.Tr("Loggers");
private static readonly string s_loggersTooltip = L10n.Tr("List of Loggers used for this autopilot settings. If omitted, Debug.unityLogger will be used as default.");

Expand Down Expand Up @@ -91,8 +88,6 @@ public override void OnInspectorGUI()
new GUIContent(s_randomSeed, s_randomSeedTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.timeScale)),
new GUIContent(s_timeScale, s_timeScaleTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.junitReportPath)),
new GUIContent(s_junitReportPath, s_junitReportPathTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.loggerAssets)),
new GUIContent(s_loggers, s_loggersTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.reporters)),
Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ This item can also be overridden from the commandline (see below).
<dt>Lifespan</dt><dd>Specifies the execution time limit in seconds. Defaults to 300 seconds, 0 specifies unlimited operation</dd>
<dt>Random Seed</dt><dd>Specify when you want to fix the seed given to the pseudo-random number generator (optional). This is a setting related to the pseudo-random number generator used by the autopilot. To fix the seed of the pseudo-random number generator in the game itself, it is necessary to implement this setting on the game title side. </dd>
<dt>Time Scale</dt><dd>Time.timeScale. Default is 1.0</dd>
<dt>JUnit Report Path</dt><dd>Specifies the JUnit format report file output path (optional). If there are zero errors and zero failures, the autopilot run is considered to have completed successfully. </dd>
<dt>Loggers</dt><dd>Logger used for this autopilot settings. If omitted, <code>Debug.unityLogger</code> will be used as default.</dd>
<dt>Reporters</dt><dd>Reporter to be called on Autopilot terminate.</dd>
</dl>
Expand Down Expand Up @@ -201,7 +200,6 @@ For details on each argument, see the entry of the same name in the "Generate an
<dt>LIFESPAN_SEC</dt><dd>Specifies the execution time limit in seconds</dd>
<dt>RANDOM_SEED</dt><dd>Specifies when you want to fix the seed given to the pseudo-random number generator</dd>
<dt>TIME_SCALE</dt><dd>Specifies the Time.timeScale. Default is 1.0</dd>
<dt>JUNIT_REPORT_PATH</dt><dd>Specifies the JUnit-style report file output path</dd>
<dt>HANDLE_EXCEPTION</dt><dd>Overwrites whether to report when an exception occurs with TRUE/FALSE</dd>
<dt>HANDLE_ERROR</dt><dd>Overwrites whether to report when an error message is detected with TRUE/FALSE</dd>
<dt>HANDLE_ASSERT</dt><dd>Overwrites whether to report when an assert message is detected with TRUE/FALSE</dd>
Expand Down Expand Up @@ -387,7 +385,7 @@ This can be accomplished with `ParallelCompositeAgent`, but it is easier to set



## Built-in Logger
## Built-in Loggers

The following Logger types are provided. These can be used as they are, or game-title-specific custom Loggers can be implemented and used.

Expand Down Expand Up @@ -418,11 +416,24 @@ The instance of this Logger (.asset file) can have the following settings.



## Built-in Reporter
## Built-in Reporters

The following Reporter types are provided. These can be used as they are, or game-title-specific custom Reporters can be implemented and used.


### JUnitXmlReporter

A reporter that outputs report files in JUnit XML format.
If there are zero errors and zero failures, the autopilot run is considered to have completed successfully.

The instance of this Reporter (.asset file) can have the following settings.

<dl>
<dt>Output File Path</dt><dd>JUnit XML report file output path. Specify relative path from project root or absolute path. When run on player, it will be the <code>Application.persistentDataPath</code>.
It can be overwritten with the command line argument <code>-JUNIT_REPORT_PATH</code>, but be careful if multiple JUnitXmlReporters are defined, they will all be overwritten with the same value.</dd>
</dl>


### SlackReporter

A Reporter that post report to Slack.
Expand Down Expand Up @@ -717,7 +728,7 @@ git submodule add https://github.com/dena/Anjin.git Packages/com.dena.anjin
> [!WARNING]
> Required install packages for running tests (when adding to the `testables` in package.json), as follows:
> - [Unity Test Framework](https://docs.unity3d.com/Packages/com.unity.test-framework@latest) package v1.3.4 or later
> - [Test Helper](https://github.com/nowsprinting/test-helper) package v0.7.2 or later
> - [Test Helper](https://github.com/nowsprinting/test-helper) package v1.0.0 or later
Generate a temporary project and run tests on each Unity version from the command line.

Expand Down
17 changes: 14 additions & 3 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ Sceneごとに自動実行を行なうAgent設定ファイル(.asset)の対
<dt>Lifespan</dt><dd>実行時間上限を秒で指定します。デフォルトは300秒、0を指定すると無制限に動作します</dd>
<dt>Random Seed</dt><dd>疑似乱数発生器に与えるシードを固定したいときに指定します(省略可)。なお、これはオートパイロットの使用する疑似乱数発生器に関する設定であり、ゲーム本体の疑似乱数発生器シードを固定するにはゲームタイトル側での実装が必要です。</dd>
<dt>Time Scale</dt><dd>Time.timeScaleを指定します。デフォルトは1.0</dd>
<dt>JUnit Report Path</dt><dd>JUnit形式のレポートファイル出力パスを指定します(省略可)。オートパイロット実行の成否は、Unityエディターの終了コードでなくこのファイルを見て判断するのが確実です。errors, failuresともに0件であれば正常終了と判断できます。</dd>
<dt>Loggers</dt><dd>オートパイロットが使用するLogger指定します。省略時は <code>Debug.unityLogger</code> がデフォルトとして使用されます</dd>
<dt>Reporters</dt><dd>オートパイロット終了時に通知を行なうReporterを指定します</dd>
</dl>
Expand Down Expand Up @@ -204,7 +203,6 @@ $(UNITY) \
<dt>LIFESPAN_SEC</dt><dd>実行時間上限を秒で指定します</dd>
<dt>RANDOM_SEED</dt><dd>疑似乱数発生器に与えるシードを固定したいときに指定します</dd>
<dt>TIME_SCALE</dt><dd>Time.timeScaleを指定します。デフォルトは1.0</dd>
<dt>JUNIT_REPORT_PATH</dt><dd>JUnit形式のレポートファイル出力パスを指定します</dd>
<dt>HANDLE_EXCEPTION</dt><dd>例外を検知したときに通知を行なうかを TRUE/ FALSEで上書きします</dd>
<dt>HANDLE_ERROR</dt><dd>エラーを検知したときに通知を行なうかを TRUE/ FALSEで上書きします</dd>
<dt>HANDLE_ASSERT</dt><dd>アサート違反を検知したときに通知を行なうかを TRUE/ FALSEで上書きします</dd>
Expand Down Expand Up @@ -428,6 +426,19 @@ SerialCompositeAgentと組み合わせることで、一連の操作を何周も
以下のReporterタイプが用意されています。これらをそのまま使用することも、ゲームタイトル固有のカスタムReporterを実装して使用することも可能です。


### JUnitXmlReporter

JUnit XMLフォーマットのレポートファイルを出力するReporterです。
オートパイロット実行の成否は、Unityエディターの終了コードでなくこのファイルを見て判断するのが確実です。errors, failuresともに0件であれば正常終了と判断できます。

このReporterのインスタンス(.assetファイル)には以下を設定できます。

<dl>
<dt>出力ファイルパス</dt><dd>JUnit XMLレポートファイルの出力パス。プロジェクトルートからの相対パスまたは絶対パスを指定します。プレイヤー実行では相対パスの起点は <code>Application.persistentDataPath</code> になります。
コマンドライン引数 <code>-JUNIT_REPORT_PATH</code> で上書きできますが、複数のJUnitXmlReporterを定義しているとき、すべて同じ値で上書きされますので注意してください。</dd>
</dl>


### SlackReporter

Slackにレポート送信するReporterです。
Expand Down Expand Up @@ -729,7 +740,7 @@ git submodule add https://github.com/dena/Anjin.git Packages/com.dena.anjin
> [!WARNING]
> Anjinパッケージ内のテストを実行するためには、次のパッケージのインストールが必要です。
> - [Unity Test Framework](https://docs.unity3d.com/Packages/com.unity.test-framework@latest) package v1.3.4 or later
> - [Test Helper](https://github.com/nowsprinting/test-helper) package v0.7.2 or later
> - [Test Helper](https://github.com/nowsprinting/test-helper) package v1.0.0 or later
テスト専用のUnityプロジェクトを生成し、Unityバージョンを指定してテストを実行するには、次のコマンドを実行します。

Expand Down
8 changes: 0 additions & 8 deletions Runtime/Autopilot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class Autopilot : MonoBehaviour, ITerminatable
private LogMessageHandler _logMessageHandler;
private AutopilotState _state;
private AutopilotSettings _settings;
private float _startTime;
private bool _isTerminating;

private void Start()
Expand Down Expand Up @@ -85,7 +84,6 @@ private void Start()
Time.timeScale = _settings.timeScale;
}

_startTime = Time.realtimeSinceStartup;
_logger.Log("Launched autopilot");
}

Expand Down Expand Up @@ -140,12 +138,6 @@ public async UniTask TerminateAsync(ExitCode exitCode, string message = null, st
await _settings.Reporter.PostReportAsync(message, stackTrace, exitCode, token);
}

if (_state.settings != null && !string.IsNullOrEmpty(_state.settings.junitReportPath))
{
var time = Time.realtimeSinceStartup - _startTime;
JUnitReporter.Output(_state.settings.junitReportPath, (int)exitCode, message, stackTrace, time);
}

Destroy(this.gameObject);

_logger.Log("Terminate Autopilot");
Expand Down
Loading

0 comments on commit c675058

Please sign in to comment.