Skip to content

Commit

Permalink
Merge pull request #42 from nowsprinting/chore/fix_tests
Browse files Browse the repository at this point in the history
Fix tests running on Linux editor
  • Loading branch information
Kuniwak authored Apr 15, 2024
2 parents fdf6be0 + 50b42f8 commit 3d0e2cf
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 96 deletions.
9 changes: 5 additions & 4 deletions Tests/Editor/UI/Settings/AutopilotSettingsEditorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IEnumerator UnityTearDown()
}

[UnityTest]
public IEnumerator Launch_RunAutopilotOnPlayMode()
public IEnumerator Launch_OnEditMode_RunAutopilotOnPlayMode()
{
var testSettings = AssetDatabase.LoadAssetAtPath<AutopilotSettings>(
"Packages/com.dena.anjin/Tests/TestAssets/AutopilotSettingsForTests.asset");
Expand All @@ -57,17 +57,18 @@ public IEnumerator Launch_RunAutopilotOnPlayMode()
editor.Launch(state); // Note: Can not call editor.OnInspectorGUI() and GUILayout.Button()

yield return new WaitForDomainReload(); // Wait for domain reloading by switching play mode
Assume.That(EditorApplication.isPlaying, Is.True, "Switched to play mode");

state = AutopilotState.Instance; // Reacquire because lost in domain reloading
Assert.That(state.launchFrom, Is.EqualTo(LaunchType.EditorEditMode));
Assert.That(state.IsRunning, Is.True, "AutopilotState is running");

var autopilot = Object.FindObjectOfType<Autopilot>();
Assert.That((bool)autopilot, Is.True, "Autopilot object is alive");
Assert.That((bool)autopilot.gameObject, Is.True, "Autopilot object is alive");
}

[UnityTest]
public IEnumerator Launch_RunAutopilot_CallMethodWithInitializeOnLaunchAutopilotAttribute()
// Note: This test about InitializeOnLaunchAutopilotAttribute
public IEnumerator Launch_CallMethodWithInitializeOnLaunchAutopilotAttribute()
{
FakeInitializeOnLaunchAutopilot.Reset();

Expand Down
18 changes: 9 additions & 9 deletions Tests/Runtime/AgentDispatcherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using DeNA.Anjin.Settings;
using DeNA.Anjin.Utilities;
using NUnit.Framework;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand Down Expand Up @@ -41,11 +40,9 @@ private static AutopilotSettings CreateAutopilotSettings()
return testSettings;
}

private const string TestAgentPath = "Packages/com.dena.anjin/Tests/TestAssets/DoNothingAgentForTests.asset";

private static DoNothingAgent LoadTestAgent(string name = nameof(DoNothingAgent))
private static DoNothingAgent CreateDoNothingAgent(string name = nameof(DoNothingAgent))
{
var doNothingAgent = AssetDatabase.LoadAssetAtPath<DoNothingAgent>(TestAgentPath);
var doNothingAgent = ScriptableObject.CreateInstance<DoNothingAgent>();
doNothingAgent.name = name;
return doNothingAgent;
}
Expand All @@ -65,7 +62,10 @@ public void DispatchByScene_DispatchAgentBySceneAgentMaps()
const string ActualAgentName = nameof(DoNothingAgent);

var settings = CreateAutopilotSettings();
settings.sceneAgentMaps.Add(new SceneAgentMap { scenePath = TestScenePath, agent = LoadTestAgent() });
settings.sceneAgentMaps.Add(new SceneAgentMap
{
scenePath = TestScenePath, agent = CreateDoNothingAgent()
});

var logger = new ConsoleLogger(Debug.unityLogger.logHandler);
var randomFactory = new RandomFactory(0);
Expand All @@ -82,7 +82,7 @@ public void DispatchByScene_DispatchFallbackAgent()
const string ActualAgentName = "Fallback";

var settings = CreateAutopilotSettings();
settings.fallbackAgent = LoadTestAgent(ActualAgentName);
settings.fallbackAgent = CreateDoNothingAgent(ActualAgentName);

var logger = new ConsoleLogger(Debug.unityLogger.logHandler);
var randomFactory = new RandomFactory(0);
Expand Down Expand Up @@ -111,8 +111,8 @@ public void DispatchByScene_DispatchObserverAgent()
const string ActualAgentName = "Observer";

var settings = CreateAutopilotSettings();
settings.fallbackAgent = LoadTestAgent();
settings.observerAgent = LoadTestAgent(ActualAgentName);
settings.fallbackAgent = CreateDoNothingAgent();
settings.observerAgent = CreateDoNothingAgent(ActualAgentName);

var logger = new ConsoleLogger(Debug.unityLogger.logHandler);
var randomFactory = new RandomFactory(0);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Runtime/ArgumentCapture/ArgumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This software is released under the MIT License.

using NUnit.Framework;
using TestHelper.Attributes;
using UnityEngine.TestTools.Utils;

namespace DeNA.Anjin.ArgumentCapture
Expand All @@ -12,7 +13,7 @@ namespace DeNA.Anjin.ArgumentCapture
/// This is actually a test of <c>ArgumentCapture</c>.
/// </summary>
[TestFixture]
[Category("IgnoreGUI")]
[IgnoreWindowMode("Need command line arguments")]
public class ArgumentTest
{
[Test]
Expand Down
5 changes: 3 additions & 2 deletions Tests/Runtime/LauncherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace DeNA.Anjin
{
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor)] // Fail on Unity 2019 Linux editor
[SuppressMessage("ApiDesign", "RS0030")]
public class LauncherTest
{
Expand Down Expand Up @@ -66,7 +66,8 @@ public async Task Stop_TerminateAutopilotAndKeepPlayMode()
var state = AutopilotState.Instance;
editor.Launch(state);
await Task.Delay(2000);
await editor.Stop(); // Note: If Autopilot stops for life before Stop, a NullReference exception is raised here.
await editor.Stop();
// Note: If Autopilot stops for life before Stop, a NullReference exception is raised here.

Assert.That(state.IsRunning, Is.False, "AutopilotState is terminated");
Assert.That(EditorApplication.isPlaying, Is.True, "Keep play mode");
Expand Down
16 changes: 0 additions & 16 deletions Tests/TestAssets/DoNothingAgentForTests.asset

This file was deleted.

8 changes: 0 additions & 8 deletions Tests/TestAssets/DoNothingAgentForTests.asset.meta

This file was deleted.

15 changes: 0 additions & 15 deletions Tests/TestAssets/StubImmediatelyErrorAgentForTests.asset

This file was deleted.

8 changes: 0 additions & 8 deletions Tests/TestAssets/StubImmediatelyErrorAgentForTests.asset.meta

This file was deleted.

Loading

0 comments on commit 3d0e2cf

Please sign in to comment.