Implementation of ITestAssemblyRunner
Наследование: ITestAssemblyRunner
Пример #1
0
    static void RunAllTestsIOS()
    {
        try {
            AltUnityTesterEditor.InitEditorConfiguration();
            UnityEngine.Debug.Log("Started running test");
            System.Reflection.Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
            System.Reflection.Assembly   assembly   = assemblies.FirstOrDefault(assemblyName => assemblyName.GetName().Name.Equals("Assembly-CSharp-Editor"));

            var testSuite2 = (NUnit.Framework.Internal.TestSuite) new NUnit.Framework.Api.DefaultTestAssemblyBuilder().Build(assembly, new System.Collections.Generic.Dictionary <string, object>());

            NUnit.Framework.Internal.Filters.OrFilter filter = new NUnit.Framework.Internal.Filters.OrFilter();
            foreach (var test in testSuite2.Tests)
            {
                foreach (var t in test.Tests)
                {
                    UnityEngine.Debug.Log(t.FullName);
                    filter.Add(new NUnit.Framework.Internal.Filters.FullNameFilter(t.FullName));
                }
            }

            NUnit.Framework.Interfaces.ITestListener listener = new TestRunListener(null);
            var testAssemblyRunner = new NUnit.Framework.Api.NUnitTestAssemblyRunner(new NUnit.Framework.Api.DefaultTestAssemblyBuilder());
            testAssemblyRunner.Load(assembly, new System.Collections.Generic.Dictionary <string, object>());
            var result = testAssemblyRunner.Run(listener, filter);
            if (result.FailCount > 0)
            {
                UnityEditor.EditorApplication.Exit(1);
            }
        } catch (System.Exception e) {
            UnityEngine.UnityEngine.Debug.LogError(e);
            UnityEditor.EditorApplication.Exit(1);
        }
    }
        public TestResult Run(string exePath, string exercise)
        {
            if(!File.Exists(exePath))
                throw new SwpTestToolException("Der angegebene Pfad führt zu keiner Exe Datei");

            TypeProvider.Initialize(_loggerFacade, exePath);

            var exerciseTestDefintion = ExerciseTestDefintionFactory.Get(exercise);

            var defaultTestAssemblyBuilder = new DefaultTestAssemblyBuilder();
            var nUnitTestAssemblyRunner = new NUnitTestAssemblyRunner(defaultTestAssemblyBuilder);

            var testGroupResults = new TestResult();

            foreach (var testDefintion in exerciseTestDefintion.TestDefintions)
            {
                var typeMappingContainer = new TypeMappingContainer();
                testDefintion.RegisterTypeMappings(typeMappingContainer);
                TypeProvider.RegisterTypeMappings(typeMappingContainer);

                if(!TypeProvider.CheckIfAttributeAssemblyExists()) break;
                if(!TypeProvider.CheckCorrectVersionOfAttributeAssembly(testDefintion.GetAssemblyIdentifier)) break;

                var testListener = new CustomTestListener(testDefintion.TestGroupName);
                nUnitTestAssemblyRunner.Load(Assembly.GetAssembly(testDefintion.GetAssemblyIdentifier), new Dictionary<string, string>());
                nUnitTestAssemblyRunner.Run(testListener, new TestMethodFilter());
                testGroupResults.AddTestCaseGroupResult(testListener.TestCaseGroupResult);
            }

            return testGroupResults;
        }
Пример #3
0
        public void CreateResult()
        {
            var mockAssembly = typeof (MockAssembly).Assembly;
            var emptySettings = new Dictionary<string, object>();

            var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
            runner.Load(mockAssembly, emptySettings);
            var xmlText = runner.Run(TestListener.NULL, Framework.Internal.TestFilter.Empty).ToXml(true).OuterXml;
            var engineResult = AddMetadata(new TestEngineResult(xmlText));
            _result = engineResult.Xml;

            Assert.NotNull(_result, "Unable to create report result.");
        }
Пример #4
0
 private void RunTests(ITestFilter testFilter)
 {
     MissingAPILambdaFunctions.Initialize();
     ITestAssemblyRunner runner = null;
     if (Utils.IsIL2CPP)
         runner = new NUnitTestAssemblyRunner(new UnityTestAssemblyBuilder());
     else
         runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
     var currentAssembly = this.GetType().Assembly;
     var options = new Dictionary<string, string>();
     var tests = runner.Load(currentAssembly, options);
     var testListener = new TestListener();
     var result = runner.Run(testListener, testFilter);
     TestDriver.Instance.OnTestFinished(this.HttpClient, testListener.FailedTestsCases);
 }
Пример #5
0
        public bool Execute()
        {
            var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
            var currentAssembly = typeof(TestRunner).GetTypeInfo().Assembly;
            var options = new Dictionary<string, string>();
            var tests = runner.Load(currentAssembly, options);

            var result = runner.Run(this, this.Filter);
            runner.WaitForCompletion(int.MaxValue);

            var success =
                result.FailCount == 0 &&
                result.InconclusiveCount == 0 &&
                result.SkipCount == 0;
            return success;
        }
Пример #6
0
        public void Setup()
        {
            var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());

            ActionAttributeFixture.ClearResults();

            IDictionary options = new Hashtable();
            options["LOAD"] = new string[] { "NUnit.TestData.ActionAttributeTests" };
            // No need for the overhead of parallel execution here
            options["NumberOfTestWorkers"] = 0;

            Assert.NotNull(runner.Load(ASSEMBLY_PATH, options), "Assembly not loaded");
            Assert.That(runner.LoadedTest.RunState, Is.EqualTo(RunState.Runnable));

            _result = runner.Run(TestListener.NULL, TestFilter.Empty);

            _numEvents = ActionAttributeFixture.Events.Count;
        }
Пример #7
0
    public static void RunTests(TestRunMode testMode)
    {
        UnityEngine.Debug.Log("Started running test");
        System.Reflection.Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
        System.Reflection.Assembly   assembly   = assemblies.FirstOrDefault(assemblyName => assemblyName.GetName().Name.Equals("Assembly-CSharp-Editor"));

        var filters = AddTestToBeRun(testMode);

        NUnit.Framework.Interfaces.ITestListener listener = new TestRunListener(CallRunDelegate);
        var testAssemblyRunner = new NUnit.Framework.Api.NUnitTestAssemblyRunner(new NUnit.Framework.Api.DefaultTestAssemblyBuilder());

        testAssemblyRunner.Load(assembly, new System.Collections.Generic.Dictionary <string, object>());
        progress = 0;
        total    = filters.Filters.Count;
        System.Threading.Thread runTestThread = new System.Threading.Thread(() => {
            var result = testAssemblyRunner.Run(listener, filters);
            SetTestStatus(result);
            AltUnityTesterEditor.isTestRunResultAvailable = true;
            AltUnityTesterEditor.selectedTest             = -1;
        });

        runTestThread.Start();
        if (AltUnityTesterEditor.EditorConfiguration.platform != Platform.Editor)
        {
            float previousProgres = progress - 1;
            while (runTestThread.IsAlive)
            {
                if (previousProgres == progress)
                {
                    continue;
                }
                UnityEditor.EditorUtility.DisplayProgressBar(progress == total ? "This may take a few seconds" : _testName,
                                                             progress + "/" + total, progress / total);
                previousProgres = progress;
            }
        }

        runTestThread.Join();
        if (AltUnityTesterEditor.EditorConfiguration.platform != Platform.Editor)
        {
            AltUnityTesterEditor.needsRepaiting = true;
            UnityEditor.EditorUtility.ClearProgressBar();
        }
    }
Пример #8
0
        private bool Execute()
        {
            try
            {
                FailedTestMethods = new List<TestMethod>();

                if (!IsInternetAvailable())
                {
                    WriteInfo("Internet is not available, exiting");
                    return false;
                }

                WriteInfo("Setting up runner...");
                var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
                var currentAssembly = typeof(TestRunner).GetTypeInfo().Assembly;
                var options = new Dictionary<string, string>();
                var tests = runner.Load(currentAssembly, options);

                WriteInfo("Running tests...");
                var result = runner.Run(this, this.Filter);
                runner.WaitForCompletion(int.MaxValue);

                var success = result.HasTestSucceeded();

                WriteInfo("All tests executed");
                WriteInfo("Time elapsed: {0}", TimeSpan.FromSeconds(result.Duration));

                if (!success)
                {
                    var failedMethodNames = FailedTestMethods.Select(tm => tm.Name).ToList();
                    WriteInfo("Failed methods: {0}", string.Join(", ", failedMethodNames));
                }

                // optionally, write result as xml
                //WriteInfo("Test results as XML: {0}", result.ToXml(true).OuterXml);

                PushLog(success);

                return success;
            }
            catch(Exception e)
            {
                WriteError("Encountered catastrophic error during test execution: {0}", e.ToString());
                return false;
            }
        }
Пример #9
0
        private bool Execute()
        {
            if (!IsInternetAvailable())
            {
                WriteInfo("Internet is not available, exiting");
                return false;
            }
            
            WriteInfo("Setting up runner...");
            var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
            var currentAssembly = typeof(TestRunner).GetTypeInfo().Assembly;
            var options = new Dictionary<string, string>();
            var tests = runner.Load(currentAssembly, options);

            WriteInfo("Running tests...");
            var result = runner.Run(this, this.Filter);
            runner.WaitForCompletion(int.MaxValue);

            var success =
                result.FailCount == 0 &&
                result.InconclusiveCount == 0 &&
                result.SkipCount == 0;

            WriteInfo("All tests executed");
            WriteInfo("Time elapsed: {0}", TimeSpan.FromSeconds(result.Duration));

            // optionally, write result as xml
            //WriteInfo("Test results as XML: {0}", result.ToXml(true).OuterXml);

            PushLog(success);

            return success;
        }
Пример #10
0
		async void RunTests(CategoryFilter filter = null)
		{
			if (!startButton.Enabled)
				return;
			startButton.Enabled = false;
			var keywords = search.Text;
			Log.Write(null, "Starting tests...");
			var testPlatform = useTestPlatform.Checked == true ? new TestPlatform() : Platform;
			try
			{
				await Task.Run(() =>
				{
					using (Platform.ThreadStart())
					{
						try
						{
							var listener = new TestListener { Application = Application.Instance }; // use running application for logging

							var builder = new DefaultTestAssemblyBuilder();
							var runner = new NUnitTestAssemblyRunner(builder);
							var settings = new Dictionary<string, object>();
							var result = new MultipleTestResult();
							if (filter != null)
								filter.SkipCount = 0;
							foreach (var assembly in ((TestApplication)TestApplication.Instance).TestAssemblies)
							{
								runner.Load(assembly, settings);

								filter = filter ?? new CategoryFilter();
								filter.Application = Application.Instance;
								filter.ExecutingAssembly = assembly;
								if (testPlatform is TestPlatform)
									filter.IncludeCategories.Add(UnitTests.TestUtils.TestPlatformCategory);
								else
									filter.IncludeCategories.RemoveAll(r => r == UnitTests.TestUtils.TestPlatformCategory);
								filter.Keyword = keywords;
								using (testPlatform.Context)
								{
									result.Results.Add(runner.Run(listener, filter));
								}
							}
							var writer = new StringWriter();
							writer.WriteLine(result.FailCount > 0 ? "FAILED" : "PASSED");
							writer.WriteLine("\tPass: {0}, Fail: {1}, Skipped: {2}, Inconclusive: {3}", result.PassCount, result.FailCount, result.SkipCount + filter.SkipCount, result.InconclusiveCount);
							writer.Write("\tDuration: {0}", result.Duration);
							Application.Instance.Invoke(() => Log.Write(null, writer.ToString()));
						}
						catch (Exception ex)
						{
							Application.Instance.Invoke(() => Log.Write(null, "Error running tests: {0}", ex));
						}
						finally
						{
							Application.Instance.Invoke(() => startButton.Enabled = true);
						}
					}
				});
			}
			catch (Exception ex)
			{
				Log.Write(null, "Error running tests\n{0}", ex);
			}
		}
Пример #11
0
        private async Task ExecuteTestsAync()
        {
            Running = true;
            Results = null;

            var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
            foreach(var testAssembly in _testAssemblies)
                runner.Load(testAssembly, new Dictionary<string, string>());

            ITestResult result = await Task.Run(() => runner.Run(TestListener.NULL, TestFilter.Empty));
            Results = new ResultSummary(result);

            Running = false;
        }
Пример #12
0
 async Task<NUnitTestAssemblyRunner> LoadTestAssembliesAsync()
 {
     var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
     foreach (var testAssembly in _testAssemblies)
         await Task.Run(() => runner.Load(testAssembly, new Dictionary<string, string>()));
     return runner;
 }