Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests running on Linux editor #42

Merged
merged 7 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mysterious...


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.

This file was deleted.

Loading