Exemplo n.º 1
0
        public void ConstructorShouldPopulateSettings()
        {
            string runSettingxml =
                @"<RunSettings>
                     <MSTest>
                        <ForcedLegacyMode>True</ForcedLegacyMode>
                        <SettingsFile>DummyPath\TestSettings1.testsettings</SettingsFile>
                     </MSTest>
                   </RunSettings>";

            this.testablePlatformServiceProvider.MockSettingsProvider.Setup(sp => sp.Load(It.IsAny <XmlReader>()))
            .Callback((XmlReader actualReader) =>
            {
                if (actualReader != null)
                {
                    actualReader.Read();
                    actualReader.ReadInnerXml();
                }
            });

            MSTestSettings adapterSettings    = MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsName);
            var            assemblyEnumerator = new UnitTestRunner(adapterSettings);

            Assert.IsTrue(MSTestSettings.CurrentSettings.ForcedLegacyMode);
            Assert.AreEqual("DummyPath\\TestSettings1.testsettings", MSTestSettings.CurrentSettings.TestSettingsFile);
        }
        /// <summary>   Runs the tests. </summary>
        /// <returns>   The Results of the test run. </returns>
        public TestRunnerResults Run()
        {
            var testDeployer = new TestDeployer();

            var deploymentPath = testDeployer.DeployItems(this.runnerSettings.TestAssemblyFullPath);

            var testRunner = new UnitTestRunner(deploymentPath, this.runnerSettings.TestAssemblyFullName, false, 1000);

            var testResults = this.runnerSettings.TestsToRun.ToDictionary(
                x => x,
                x => testRunner.RunSingleTest(x.TestName, x.TestClassName, false));

            foreach (var result in testResults)
            {
                if (result.Value.Outcome == UnitTestOutcome.Passed)
                {
                    Console.WriteLine($"MSTest: {result.Key.TestClassName}.{result.Key.TestName} Test Case Passed");
                }
                else
                {
                    Console.WriteLine($"MSTest: {result.Key} Test Case Failed with error ${result.Value.ErrorMessage}");
                }
            }

            return(new TestRunnerResults(true, TestRunnerType.MSTest));
        }
Exemplo n.º 3
0
        public void RunSingleTestShouldCallAssemblyInitializeAndClassInitializeMethodsInOrder()
        {
            var mockReflectHelper = new Mock <ReflectHelper>();

            this.unitTestRunner = new UnitTestRunner(new MSTestSettings(), mockReflectHelper.Object);

            var type       = typeof(DummyTestClassWithInitializeMethods);
            var methodInfo = type.GetMethod("TestMethod");
            var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny <bool>()))
            .Returns(Assembly.GetExecutingAssembly());
            mockReflectHelper.Setup(
                rh =>
                rh.IsAttributeDefined(
                    type.GetMethod("AssemblyInitialize"),
                    typeof(UTF.AssemblyInitializeAttribute),
                    It.IsAny <bool>())).Returns(true);

            var validator = 1;

            DummyTestClassWithInitializeMethods.AssemblyInitializeMethodBody = () => { validator <<= 2; };
            DummyTestClassWithInitializeMethods.ClassInitializeMethodBody    = () => { validator >>= 2; };

            this.unitTestRunner.RunSingleTest(testMethod, this.testRunParameters);

            Assert.AreEqual(1, validator);
        }
Exemplo n.º 4
0
        public UnitTestSection()
        {
            runner             = new UnitTestRunner(((TestApplication)TestApplication.Instance).TestAssemblies);
            unitTestPanel      = new UnitTestPanel(runner, false);
            unitTestPanel.Log += (sender, e) => Log.Write(null, e.Message);

            Content = unitTestPanel;
        }
Exemplo n.º 5
0
        public void TestInit()
        {
            this.unitTestRunner    = new UnitTestRunner(false);
            this.testRunParameters = new Dictionary <string, object>();
            this.testablePlatformServiceProvider = new TestablePlatformServiceProvider();

            PlatformServiceProvider.Instance = this.testablePlatformServiceProvider;
        }
 private void ExecuteTestSuite( TestSuite suite, UnitTestRunner.ITestRunnerCallback testRunnerEventListener, TestFilter filter )
 {
     EventListener eventListener;
     if (testRunnerEventListener == null)
         eventListener = new NullListener ();
     else
         eventListener = new TestRunnerEventListener (testRunnerEventListener);
     suite.Run(eventListener, GetFilter(filter));
 }
Exemplo n.º 7
0
        public void TestInit()
        {
            this.testRunParameters = new Dictionary <string, object>();
            this.testablePlatformServiceProvider = new TestablePlatformServiceProvider();

            PlatformServiceProvider.Instance = this.testablePlatformServiceProvider;

            this.unitTestRunner = new UnitTestRunner(this.GetSettingsWithDebugTrace(false));
        }
Exemplo n.º 8
0
        public static void EnterTestReadyLoop()
        {
            Screen.Color = 0x0;
            Screen.Clear();
            Screen.GotoTop();
            Screen.Color = 0x0E;
            Screen.Write("MOSA OS Version 1.6 - UnitTest");
            Screen.NextLine();
            Screen.NextLine();

            UnitTestQueue.Setup();
            UnitTestRunner.Setup();

            UnitTestRunner.EnterTestReadyLoop();
        }
Exemplo n.º 9
0
        public Dictionary <string, string> ToReplacementDictionary(Dictionary <string, string> dct)
        {
            dct.Add("$aurelia_project_name$", AureliaProjectName);
            dct.Add("$aurelia_module_loader$", ModuleLoader.ToString());
            dct.Add("$aurelia_http_type$", HttpType.ToString());
            dct.Add("$aurelia_transpiler$", Transpiler.ToString());
            dct.Add("$aurelia_minification$", Minification.ToString());
            dct.Add("$aurelia_css_processing$", CSSProcessing.ToString());
            dct.Add("$aurelia_unit_ruinner$", UnitTestRunner.ToString());
            dct.Add("$aurelia_integration_testing$", IntegrationTesting.ToString());
            dct.Add("$aurelia_install_after$", InstallAfter.ToString());
            dct.Add("$aurelia_build_after$", BuildAfter.ToString());

            return(dct);
        }
		public void RunTests(string[] tests, UnitTestRunner.ITestRunnerCallback testRunnerEventListener)
		{
			List<String> assemblies = GetAssemblies();
			TestSuite suite = PrepareTestSuite(assemblies);

			ITestFilter filter = TestFilter.Empty;
			if (tests != null && tests.Any())
				filter = new SimpleNameFilter(tests);
			
			if (testRunnerEventListener!=null)
				testRunnerEventListener.RunStarted(suite.TestName.FullName, suite.TestCount);
			
			ExecuteTestSuite(suite, testRunnerEventListener, filter);
			
			if (testRunnerEventListener!=null)
				testRunnerEventListener.RunFinished();
		}
Exemplo n.º 11
0
        public void RunTests(TestFilter filter, UnitTestRunner.ITestRunnerCallback testRunnerEventListener) {
            try {
                if (testRunnerEventListener != null)
                { testRunnerEventListener.RunStarted(testSuite.TestName.FullName, testSuite.TestCount); }

                ExecuteTestSuite(testSuite, testRunnerEventListener, filter);

                if (testRunnerEventListener != null)
                { testRunnerEventListener.RunFinished(); }

            } catch (Exception e) {
                Debug.LogException(e);

                if (testRunnerEventListener != null)
                { testRunnerEventListener.RunFinishedException(e); }
            }
        }
Exemplo n.º 12
0
        public TestList()
        {
            String dir = AppDomain.CurrentDomain.BaseDirectory;


            if (dir.Contains("World of Warcraft"))
            {
                wowDir = dir.Substring(0, dir.IndexOf("\\", dir.IndexOf("World of Warcraft")));
            }
            else
            {
                // Program not running from a wow directory. Using C:\Games\World of Warcraft
                wowDir = @"C:\Games\World of Warcraft";
            }

            runner = new UnitTestRunner(wowDir + @"\Interface\AddOns\GHP\TEST");

            Update();
        }
Exemplo n.º 13
0
        public override void Run(BuildContext context)
        {
            var unitTestConfig = new TestConfig
            {
                ResultsFolder = context.RepoRoot.Combine("TestResults"),
                TestCsProject = context.RepoRoot.CombineWithFilePath("Tests/Tests.csproj")
            };

            UnitTestRunner runner = new UnitTestRunner(context, unitTestConfig);

            if (context.Argument("coverage", false))
            {
                runner.RunCodeCoverage("+[*]SethCS*");
            }
            else
            {
                runner.RunTests();
            }
        }
Exemplo n.º 14
0
        public void RunCleanupShouldReturnCleanupResultsWithDebugTraceLogsSetIfDebugTraceEnabled()
        {
            this.unitTestRunner = new UnitTestRunner(this.GetSettingsWithDebugTrace(true));
            var type       = typeof(DummyTestClassWithCleanupMethods);
            var methodInfo = type.GetMethod("TestMethod");
            var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny <bool>()))
            .Returns(Assembly.GetExecutingAssembly());

            StringWriter writer = new StringWriter(new StringBuilder("DummyTrace"));

            this.testablePlatformServiceProvider.MockTraceListener.Setup(tl => tl.GetWriter()).Returns(writer);

            this.unitTestRunner.RunSingleTest(testMethod, this.executionRecorderWrapper, this.testRunParameters);

            var cleanupresult = this.unitTestRunner.RunCleanup();

            Assert.AreEqual(cleanupresult.DebugTrace, "DummyTrace");
        }
Exemplo n.º 15
0
		public UnitTestResult[] RunTests(string[] tests, UnitTestRunner.ITestRunnerCallback testRunnerEventListener)
		{
			List<String> assemblies = GetAssemblies();
			TestSuite suite = PrepareTestSuite(assemblies);

			ITestFilter filter = TestFilter.Empty;
			if (tests != null && tests.Any())
				filter = new SimpleNameFilter(tests);

			testRunnerEventListener.RunStarted(suite.TestName.FullName, suite.TestCount);

			NUnit.Core.TestResult result = ExecuteTestSuite(suite,
												testRunnerEventListener,
												filter);
			UpdateTestResults(result);

			testRunnerEventListener.RunFinished();

			return testList.ToArray();
		}
        // ----------------- Functions -----------------

        public override void Run(MeditationLogContext context)
        {
            TestConfig testConfig = new TestConfig
            {
                ResultsFolder = context.RepoRoot.Combine(new DirectoryPath("TestResults")),
                TestCsProject = context.SrcPath.CombineWithFilePath(new FilePath("Meditu.UnitTests/Meditu.UnitTests.csproj"))
            };
            UnitTestRunner runner = new UnitTestRunner(context, testConfig);

            TestArguments args = context.CreateFromArguments <TestArguments>();

            if (args.RunWithCodeCoverage)
            {
                runner.RunCodeCoverage(TestArguments.CoverageFilter);
            }
            else
            {
                runner.RunTests();
            }
        }
Exemplo n.º 17
0
        public JsonResult RunUnitTest(int QuestionId, Guid UnitTestId)
        {
            Object returnData;

            try
            {
                var service    = IocContainer.Container.GetInstance <IQuestionService>();
                var question   = service.Get(QuestionId, null);
                var test       = question.ExerciseQuestionUnitTests.Single(x => x.ExerciseQuestionUnitTestId == UnitTestId);
                var testRunner = new UnitTestRunner();
                var passed     = testRunner.RunUnitTest(test, GetCurrentUser());
                returnData = new { Success = true, Passed = passed };
                return(Json(returnData, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                returnData = new { Success = false, ErrorMessage = "Error running unit test - " + ex.Message };
                Trace.WriteLine(String.Format("Error running unit test - {0}", ex.Message));
                return(Json(returnData, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 18
0
    public static int Main(string[] args)
    {
        // Not using UnityInstance.Initialize here because it also creates a world, and some tests exist
        // that expect to handle their own world life cycle which currently conflicts with our world design
        UnityInstance.BurstInit();

        DotsRuntime.Initialize();

        TempMemoryScope.EnterScope();
        // Static storage used for the whole lifetime of the process. Create it once here
        // so heap tracking tests won't fight over the storage causing alloc/free mismatches
        WordStorage.Initialize();

        // TypeManager initialization uses temp memory, so let's free it before creating a global scope
        Unity.Entities.TypeManager.Initialize();
        TempMemoryScope.ExitScope();

        // Should have stack trace with tests
        NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;

        int result = 0;

#if UNITY_PORTABLE_TEST_RUNNER
        double start = Time.timeAsDouble;
        UnitTestRunner.Run();
        double end = Time.timeAsDouble;
        PrintResults(end - start);
#else
        result = new AutoRun().Execute(args);
#endif

        TempMemoryScope.EnterScope();
        Unity.Entities.TypeManager.Shutdown();
        WordStorage.Shutdown();
        TempMemoryScope.ExitScope();

        DotsRuntime.Shutdown();

        return(result);
    }
Exemplo n.º 19
0
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                action.Items = context.JobOption.SlnFiles;
            }

            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }


            TotalResult totalResult = context.TotalResult;

            try {
                foreach (string path in action.Items)
                {
                    UnitTestRunner runner = new UnitTestRunner(context);

                    SlnUnitTestResult total = runner.Execute(context.Branch, path);
                    if (total != null)
                    {
                        totalResult.UnitTestResults.AddRange(total.UnitTestResults);
                        totalResult.CodeCoverResults.AddRange(total.CodeCoverResults);
                    }
                }

                // 计算总结果
                int caseCount  = 0;
                int casePassed = 0;

                int totalStatements   = 0;
                int coveredStatements = 0;

                foreach (var t in totalResult.UnitTestResults)
                {
                    caseCount  += t.Total;
                    casePassed += t.Passed;
                }

                foreach (var c in totalResult.CodeCoverResults)
                {
                    totalStatements   += c.Total;
                    coveredStatements += c.Passed;
                }

                // 更新结果
                totalResult.UnitTestTotal  = caseCount;
                totalResult.UnitTestPassed = casePassed;

                if (totalStatements == 0)
                {
                    totalResult.CodeCover = 0;
                }
                else
                {
                    totalResult.CodeCover = (int)((100 * coveredStatements) / totalStatements);
                }


                context.ConsoleWrite("CodeCoverTask OK");
            }
            catch (Exception ex) {
                totalResult.UnitTestPassed = -1;
                totalResult.UnitTestTotal  = -1;
                context.ProcessException(ex);
            }
        }
Exemplo n.º 20
0
			public TestRunnerEventListener(UnitTestRunner.ITestRunnerCallback testRunnerEventListener)
			{
				this.testRunnerEventListener = testRunnerEventListener;
			}
Exemplo n.º 21
0
		private NUnit.Core.TestResult ExecuteTestSuite(TestSuite suite, UnitTestRunner.ITestRunnerCallback testRunnerEventListener, ITestFilter filter)
		{
			var result = suite.Run(new TestRunnerEventListener(testRunnerEventListener),
									filter);
			return result;
		}
Exemplo n.º 22
0
 private static void Main()
 {
     UnitTestRunner.Run(false);
     UnitTestRunner.Run(true);
 }
 public void RunTests(UnitTestRunner.ITestRunnerCallback testRunnerEventListener)
 {
     RunTests (TestFilter.Empty, testRunnerEventListener);
 }
Exemplo n.º 24
0
 static void Main()
 {
     UnitTestRunner.Run(typeof(Program).Assembly);
 }
Exemplo n.º 25
0
 static void CheckAppSettings()
 {
     TfsTask.CheckExePath();
     MsBuildTask.CheckExePath();
     UnitTestRunner.CheckExePath();
 }