private IEnumerator DoResultRoutine(DummyAgent agent, bool shouldSucceed)
        {
            // Test whether stopping actually stops running the environment.
            Assert.IsTrue(agent.Environment.IsRunning);
            try
            {
                agent.Stop(shouldSucceed);
                if (!shouldSucceed)
                {
                    Assert.Fail("Failing test should've thrown an exception.");
                }
            }
            catch (Exception e)
            {
                if (shouldSucceed)
                {
                    Assert.Fail("Successful test shoudn't have thrown an exception.");
                }
                Assert.AreEqual($"[Test manually failed] : {DummyAgent.FailReason}", e.Message);
                yield break;
            }

            // Only successful results can enter this area now.

            Assert.IsFalse(agent.Environment.IsRunning);
            // Stopping doesn't immediately terminate the environment.
            // It needs to be processed within the coroutine which the UnityTest has invoked so the success/fail indication is shown properly in the editor.
            Assert.IsFalse(agent.IsCleanupCalled);

            // Attempting to run or end should be ignored.
            agent.Run();
            Assert.IsFalse(agent.Environment.IsRunning);
            // Shouldn't throw an exception because the test is already finished.
            agent.Stop(false);

            // Test whether cleanup is called.
            yield return(null);

            Assert.IsTrue(agent.IsCleanupCalled);
        }
        private IEnumerator DoGeneralRoutine(DummyAgent agent)
        {
            Assert.IsTrue(agent.Environment.IsRunning);
            Assert.IsTrue(agent.IsInitCalled);
            Assert.IsFalse(agent.IsUpdateCalled);
            Assert.IsFalse(agent.IsCleanupCalled);

            if (agent.Options.UseCamera)
            {
                Camera camera = Camera.main;
                Assert.IsNotNull(camera);
                Assert.IsNotNull(camera.GetComponent <AudioListener>());
            }

            if (agent.Options.DefaultRoot != null)
            {
                IRoot root = agent.Dependency.Get <IRoot>();
                Assert.IsNotNull(root);
                if (agent.Options.UseCamera)
                {
                    Assert.AreEqual(Camera.main, root.Cam);
                }
                else
                {
                    Assert.IsNull(root.Cam);
                }
                Assert.AreEqual(new Vector2(640f, 640f), root.BaseResolution);
            }

            // Using StartCoroutine here is a bit of a hack to bypass current testing limitations.
            agent.Environment.StartCoroutine(agent.Run());
            Assert.IsTrue(agent.IsInitCalled);

            if (agent.Options.UpdateMethod != null)
            {
                Assert.IsTrue(agent.IsUpdateCalled);
                Assert.AreEqual(1, agent.UpdateCalls);
                Assert.IsFalse(agent.IsCleanupCalled);

                // Test whether update is initially called after a frame.
                yield return(null);

                Assert.IsTrue(agent.IsInitCalled);
                Assert.IsTrue(agent.IsUpdateCalled);
                Assert.AreEqual(2, agent.UpdateCalls);
                Assert.IsFalse(agent.IsCleanupCalled);

                // Test whether update method is constantly called every frame.
                agent.IsUpdateCalled = false;
                yield return(null);

                Assert.IsTrue(agent.IsInitCalled);
                Assert.IsTrue(agent.IsUpdateCalled);
                Assert.AreEqual(3, agent.UpdateCalls);
                Assert.IsFalse(agent.IsCleanupCalled);
            }
            else if (agent.Options.Actions != null)
            {
                Assert.IsFalse(agent.IsKeyActionCalled);
                yield return(null);

                Assert.IsTrue(agent.IsKeyActionCalled);
                Assert.IsFalse(agent.IsCleanupCalled);
            }
            else
            {
                Assert.IsFalse(agent.Environment.IsRunning);
                Assert.IsTrue(agent.IsCleanupCalled);
            }
        }