Ejemplo n.º 1
0
        public void LoadTest(Type testType = null, Action onCompletion = null, bool isDynamicLoad = false)
        {
            if (testType == null && TestTypes.Count > 0)
            {
                testType = TestTypes[0];
            }

            config.Set(TestBrowserSetting.LastTest, testType?.Name ?? string.Empty);

            if (testType == null)
            {
                return;
            }

            var newTest = (TestScene)Activator.CreateInstance(testType);

            const string dynamic_prefix = "dynamic";

            // if we are a dynamically compiled type (via DynamicClassCompiler) we should update the dropdown accordingly.
            if (isDynamicLoad)
            {
                toolbar.AddAssembly($"{dynamic_prefix} ({testType.Name})", testType.Assembly);
            }
            else
            {
                TestTypes.RemoveAll(t => t.Assembly.FullName.Contains(dynamic_prefix));
            }

            Assembly.Value = testType.Assembly;

            var lastTest = CurrentTest;

            CurrentTest = newTest;
            CurrentTest.OnLoadComplete += _ => Schedule(() => finishLoad(newTest, lastTest, onCompletion));

            updateButtons();
            resetRecording();

            testContentContainer.Add(new ErrorCatchingDelayedLoadWrapper(CurrentTest, isDynamicLoad)
            {
                OnCaughtError = compileFailed
            });
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Blocks execution until a provided <see cref="TestScene"/> runs to completion.
            /// </summary>
            /// <param name="test">The <see cref="TestScene"/> to run.</param>
            public void RunTestBlocking(TestScene test)
            {
                Trace.Assert(host != null, $"Ensure this runner has been loaded before calling {nameof(RunTestBlocking)}");

                bool completed = false;
                ExceptionDispatchInfo exception = null;

                void complete()
                {
                    // We want to remove the TestScene from the hierarchy on completion as under nUnit, it may have operations run on it from a different thread.
                    // This is because nUnit will reuse the same class multiple times, running a different [Test] method each time, while the GameHost
                    // is run from its own asynchronous thread.
                    RemoveInternal(test);
                    completed = true;
                }

                Schedule(() =>
                {
                    AddInternal(test);

                    Console.WriteLine($@"{(int)Time.Current}: Running {test} visual test cases...");

                    // Nunit will run the tests in the TestScene with the same TestScene instance so the TestScene
                    // needs to be removed before the host is exited, otherwise it will end up disposed

                    test.RunAllSteps(() =>
                    {
                        Scheduler.AddDelayed(complete, time_between_tests);
                    }, e =>
                    {
                        exception = ExceptionDispatchInfo.Capture(e);
                        complete();
                    });
                });

                while (!completed && host.ExecutionState == ExecutionState.Running)
                {
                    Thread.Sleep(10);
                }

                exception?.Throw();
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Blocks execution until a provided <see cref="TestScene"/> runs to completion.
 /// </summary>
 /// <param name="test">The <see cref="TestScene"/> to run.</param>
 public virtual void RunTestBlocking(TestScene test) => runner.RunTestBlocking(test);