コード例 #1
0
        public void ShowTestPicker()
        {
            var ui = new TestSelectionInterface(createTree());

            ui.Data = new SaveData();
            if (testState.GetActiveTest() != null)
            {
                ui.SelectNodeByPath(testState.GetActiveTest().ReflectedType.FullName + "." + testState.GetActiveTest().Name);
            }
            NUnitTest ret = null;

            ui.RunTestMethod += delegate(TestNode node)
            {
                ret = (NUnitTest)node.Test;
                if (ret.TestMethod == null)
                {
                    ret = null;
                    return;
                }
                pickedTest    = ret;
                pickCompleted = true;

                ui.Hide();
            };

            ui.Show();
        }
コード例 #2
0
        public void TestRunNestedTestNewProcess()
        {
            var other = new OtherProcessTestRunner(new NUnitTestRunner());
            var cls   = typeof(UtilitiesTest);
            var test  = new NUnitTest(cls.GetMethod("TestSimpleTest"), cls);

            other.Run(test);
        }
コード例 #3
0
ファイル: NUnitTask.cs プロジェクト: skolima/NAnt-new
        private void ExecuteTest(NUnitTest test)
        {
            // Set Defaults
            RunnerResult result = RunnerResult.Success;

            if (test.ToDir == null)
            {
                test.ToDir = Project.BaseDirectory;
            }
            if (test.OutFile == null)
            {
                test.OutFile = "TEST-" + test.Class;
            }

            NUnitTestData testData = test.GetTestData();

            foreach (FormatterElement element in FormatterElements)
            {
                testData.Formatters.Add(element.Data);
            }

            if (testData.Fork == true)
            {
                result = ExecuteInAppDomain(testData);
            }
            else
            {
                result = ExecuteInProc(testData);
            }

            // Handle return code:
            // If there is an error/failure and that it should halt, stop
            // everything otherwise just log a statement.
            bool errorOccurred   = (result == RunnerResult.Errors);
            bool failureOccurred = (result != RunnerResult.Success);

            if ((errorOccurred && test.HaltOnError) || (failureOccurred && test.HaltOnFailure))
            {
                // Only thrown if this test should halt as soon as the first
                // error/failure is detected.  In most cases all tests will
                // be run to get a full list of problems.
                throw new BuildException("Test " + testData.Class + " Failed", Location);
            }

            // Used for reporting the final result from the task.
            if (errorOccurred)
            {
                _errorsPresent = true;
            }
            if (failureOccurred)
            {
                _failuresPresent = true;
            }
        }
コード例 #4
0
        [PersistanceScope] // Data created when starting a test should persist!
        public void RunTestInEngine(TWEngine engine, NUnitTest test)
        {
            var oldContext = EngineFactory.Instance;

            EngineFactory.Instance = new TWEngineContext(engine);

            //TW.Graphics.Form.Hide();

            var runner = new NUnitTestRunner();

            //TODO: runner.Timeout = 10000;
            runner.RunInThisThread(test);

            DI.Get <TestSceneBuilder>().EnsureTestSceneLoaded();

            //TW.Graphics.Form.Show();

            EngineFactory.Instance = oldContext;
        }
コード例 #5
0
        private void loadTest(TWEngine engine)
        {
            engine.AddSimulator(new EngineUISimulator());
            //engine.AddSimulator(new GraphVisualizerSimulator());
            try
            {
                var test   = new NUnitTest(engineTestState.GetActiveTest(), engineTestState.GetActiveTest().ReflectedType);
                var runner = new EngineTestRunner();
                runner.RunTestInEngine(engine, test);
            }
            catch (Exception ex)
            {
                //TODO: this does not work since the error is caught in the NUnit Test Runner!!
                DI.Get <IErrorLogger>().Log(ex, "When starting test (EngineInitializer)");
            }

            loadBare(engine);

            //engine.AddSimulator(DI.Get<ModelObjectGraphSimulator>());
        }
コード例 #6
0
        private void RunTest(NUnitTest test)
        {
            // TODO: Run the test.
            string baseOutputFile = StringUtils.FormatInvariant(@"{0}\{1}", Options.OutputDirectory, test.TestName);

            string arguments = StringUtils.FormatInvariant(@"{0} /nologo /labels /run:{1} /out:{2}.txt /xml:{2}.xml /timeout:{3}",
                                                           test.DllPath, test.TestName, baseOutputFile, Computer.Timeout * 1000);

            if (Computer.WorkingDirectory != null)
            {
                arguments = StringUtils.FormatInvariant("{0} /work:{1}", arguments, Computer.WorkingDirectory);
            }

            var processStartInfo = new ProcessStartInfo(NunitPath, arguments);

            processStartInfo.CreateNoWindow  = true;
            processStartInfo.ErrorDialog     = false;
            processStartInfo.UseShellExecute = false;

            if (Computer.WorkingDirectory != null)
            {
                processStartInfo.WorkingDirectory = Computer.WorkingDirectory;
            }

            foreach (var envKeyValue in Computer.EnvironmentVariables)
            {
                Log.WriteDebug("** On Computer '{0}', setting env var '{1}' = '{2}'", Computer.Hostname, envKeyValue.Key, envKeyValue.Value);
                processStartInfo.EnvironmentVariables.Add(envKeyValue.Key, envKeyValue.Value);
            }

            Log.WriteInfo("----- Running test: '{0}' on: {1}", test.TestName, Computer.Hostname);
            Log.WriteDebug("***** Running: {0} {1}", NunitPath, arguments);
            var  process  = Process.Start(processStartInfo);
            bool finished = process.WaitForExit((Computer.Timeout + 60) * 1000);

            if (!finished)
            {
                Log.WriteWarning("Timed out when running: '{0}' on {1}!", test.TestName, Computer.Hostname);
            }

            // TODO: Add result to CompletedTests list.
            var    testResult    = new TestResult();
            string xmlOutputFile = StringUtils.FormatInvariant("{0}.xml", baseOutputFile);

            if (File.Exists(xmlOutputFile))
            {
                ParseNunitResults(xmlOutputFile, testResult);
            }
            else
            {
                testResult.Result = TestResult.ExitResult.Error;
            }

            test.TestRuns.Add(testResult);
            TestQueue.AddCompletedTest(test);

            // Print test output to stdout.
            string outputFile = StringUtils.FormatInvariant("{0}.txt", baseOutputFile);

            if (File.Exists(outputFile))
            {
                string outputContents = File.ReadAllText(outputFile);
                Log.WriteDebug(outputContents);
            }

            Log.WriteInfo("----- Test: '{0}'  Status = {1} on {2}", test.TestName, testResult.Result, Computer.Hostname);
        }