Exemplo n.º 1
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            listener.TestStarted(base.TestName);
            long ticks = DateTime.Now.Ticks;
            TestResult testResult = new TestResult(this);

            Exception existingError = null;

            _globalSetup.PrepareForTestPosition(Position, out existingError);

            if (existingError != null)
            {
                TestResultUtil.Error(testResult, existingError, null, FailureSite.SetUp);
            }
            else
            {
                List<string> traceMessages = null;
                try
                {
                    RunTestMethod(testResult, out traceMessages);
                }
                catch (Exception e)
                {
                    var globalTraceMessages = _globalSetup.GetTraceMessages();
                    TestResultUtil.Error(testResult, e, globalTraceMessages.Concat(traceMessages));
                }
            }

            double num3 = ((double)(DateTime.Now.Ticks - ticks)) / 10000000.0;
            testResult.Time = num3;
            listener.TestFinished(testResult);
            return testResult;
        }
Exemplo n.º 2
0
	    private object RunTaskAsyncMethod(TestResult testResult)
	    {
		    try
		    {
			    object task = base.RunTestMethod(testResult);

			    Reflect.InvokeMethod(method.ReturnType.GetMethod(TaskWaitMethod, new Type[0]), task);
			    PropertyInfo resultProperty = Reflect.GetNamedProperty(method.ReturnType, TaskResultProperty, TaskResultPropertyBindingFlags);

			    return resultProperty != null ? resultProperty.GetValue(task, null) : task;
		    }
		    catch (NUnitException e)
		    {
			    if (e.InnerException != null && 
					e.InnerException.GetType().FullName.Equals(SystemAggregateException))
			    {
				    IList<Exception> inner = (IList<Exception>)e.InnerException.GetType()
						.GetProperty(InnerExceptionsProperty).GetValue(e.InnerException, null);

				    throw new NUnitException("Rethrown", inner[0]);
			    }

			    throw;
		    }
	    }
Exemplo n.º 3
0
        /// <summary>
        /// Merges the specified other.
        /// </summary>
        /// <param name="source"> </param>
        /// <param name="target"> </param>
        public void Merge(TestResult source, TestResult target)
        {
            var mergedType = GetType(target);
            var otherType = GetType(source);

            if (mergedType == TestType.Project && otherType == TestType.Project)
            {
                if (string.IsNullOrEmpty(target.FullName) && !string.IsNullOrEmpty(source.FullName))
                {
                    target.Test.TestName.FullName = source.FullName;
                    target.Test.TestName.Name = source.Name;
                }
            }

            if (mergedType != otherType)
                throw new NotSupportedException("Only merging of results with same test type are supported");

            if (!target.IsSuccess && source.IsSuccess)
            {
                target.Success(source.Message);
                target.SetAgentName(source.GetAgentName());
            }

            MergeChildren(source, target);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Construct a TestNode given a TestResult
 /// </summary>
 public TestSuiteTreeNode( TestResult result )
     : base(result.Test.TestName.Name)
 {
     this.test = result.Test;
     this.result = result;
     UpdateImageIndex();
 }
Exemplo n.º 5
0
 public void SuiteFinished(TestResult suiteResult)
 {
     if (--testRecord.level == 0)
     {
         testRecord.CompleteTestSuite(suiteResult);
     }
 }
        public void TestFinished(TestResult result)
        {
            totalAssertsExecutedInThisRun = totalAssertsExecutedInThisRun + result.AssertCount;

            if (!result.IsSuccess)
                totalAssertsExecutedInThisRun++;
        }
 public void RunFinished(TestResult result)
 {
     if (m_EventListener != null)
     {
         m_EventListener.RunFinished(result);
     }
 }
Exemplo n.º 8
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            using (new global::NUnit.Core.TestContext())
            {
                var testResult = new TestResult(this);
                Log.Debug("Test Starting: " + TestName.FullName);
                listener.TestStarted(TestName);
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                switch (RunState)
                {
                    case RunState.Runnable:
                    case RunState.Explicit:
                        DoTest(_test, testResult);
                        break;
                    case RunState.NotRunnable:
                        testResult.Invalid(IgnoreReason);
                        break;
                    case RunState.Ignored:
                        testResult.Ignore(IgnoreReason);
                        break;
                    default:
                        testResult.Skip(IgnoreReason);
                        break;

                }

                stopwatch.Stop();
                testResult.Time = stopwatch.Elapsed.Seconds;

                listener.TestFinished(testResult);
                return testResult;
            }
        }
Exemplo n.º 9
0
        public void TestFinished(TestResult result)
        {
            // Put results into data table
            DataRow dr = m_results.NewRow();
            dr["test"] = result.Test.TestName;
            dr["message"] = result.Message;
            if (result.IsFailure)
                dr["message"] += result.StackTrace;
            dr["class"] = "notRun";
            dr["time"] = result.Time;

            if (result.IsSuccess && result.Executed)
            {
                dr["result"] = "Pass";
                dr["class"] = "pass";
            }

            if (result.IsFailure && result.Executed)
            {
                dr["result"] = "Fail";
                dr["class"] = "fail";
                m_failedCount++;
            }

            if (result.Executed)
                m_executedCount++;

            m_results.Rows.Add(dr);
        }
Exemplo n.º 10
0
        public void TestFinished(TestResult result)
        {
            // Put results into data table
            var dr = _results.NewRow();
            dr["test"] = result.Test.TestName;
            dr["class"] = "notRun";
            dr["time"] = result.Time;

            var message = result.Message;
            if (result.IsFailure)
                message += "\r\n" + result.StackTrace;

            if (!string.IsNullOrEmpty(message))
                message = message.Replace("\r\n", "<br/>");

            dr["message"] = message;

            if (result.IsSuccess && result.Executed)
            {
                dr["result"] = "Pass";
                dr["class"] = "pass";
            }

            if (result.IsFailure && result.Executed)
            {
                dr["result"] = "Fail";
                dr["class"] = "fail";
                _failedCount++;
            }

            if (result.Executed)
                _executedCount++;

            _results.Rows.Add(dr);
        }
Exemplo n.º 11
0
		private void InitializeXmlFile(TestResult result) 
		{
			ResultSummarizer summaryResults = new ResultSummarizer(result);

			xmlWriter.Formatting = Formatting.Indented;
			xmlWriter.WriteStartDocument(false);
			xmlWriter.WriteComment("This file represents the results of running a test suite");

			xmlWriter.WriteStartElement("test-results");

			xmlWriter.WriteAttributeString("name", summaryResults.Name);
			xmlWriter.WriteAttributeString("total", summaryResults.TestsRun.ToString());
            xmlWriter.WriteAttributeString("errors", summaryResults.Errors.ToString());
            xmlWriter.WriteAttributeString("failures", summaryResults.Failures.ToString());
            xmlWriter.WriteAttributeString("not-run", summaryResults.TestsNotRun.ToString());
            xmlWriter.WriteAttributeString("inconclusive", summaryResults.Inconclusive.ToString());
            xmlWriter.WriteAttributeString("ignored", summaryResults.Ignored.ToString());
            xmlWriter.WriteAttributeString("skipped", summaryResults.Skipped.ToString());
            xmlWriter.WriteAttributeString("invalid", summaryResults.NotRunnable.ToString());

			DateTime now = DateTime.Now;
			xmlWriter.WriteAttributeString("date", XmlConvert.ToString( now, "yyyy-MM-dd" ) );
			xmlWriter.WriteAttributeString("time", XmlConvert.ToString( now, "HH:mm:ss" ));
			WriteEnvironment();
			WriteCultureInfo();
		}
Exemplo n.º 12
0
 /// <summary>
 /// Called when a test case has finished
 /// </summary>
 /// <param name="result">The result of the test</param>
 public void TestFinished(TestResult result)
 {
     if (this.eventListener != null)
     {
         this.eventListener.TestFinished(result);
     }
 }
Exemplo n.º 13
0
 public void TestFinished(TestResult result)
 {
     testRecord.CompleteTest(result);
     string logFileName = GetLogFileName(testRecord);
     LogTestResult(logFileName, testRecord);
     testRecord.TestTime = result.Time;
 }
Exemplo n.º 14
0
	    private object RunVoidAsyncMethod(TestResult testResult)
        {
            var previousContext = SynchronizationContext.Current;
            var currentContext = new AsyncSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(currentContext);

            try
            {
                object result = base.RunTestMethod(testResult);

	            try
	            {
		            currentContext.WaitForPendingOperationsToComplete();
	            }
	            catch (Exception e)
	            {
					throw new NUnitException("Rethrown", e);		            
	            }

                return result;
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(previousContext);
            }
        }
Exemplo n.º 15
0
        TestResult RunTest(EventListener listener)
        {
            listener.TestStarted(base.TestName);

            TestResult nunitTestResult = new TestResult(this);

            if (_pendingException != null)
            {
                nunitTestResult.Failure(_pendingException.Message, _pendingException.StackTrace, FailureSite.Test);
            }
            else if (RunState == RunState.NotRunnable)
            {
                nunitTestResult.SetResult(ResultState.NotRunnable, IgnoreReason, "", FailureSite.Test);
            }
            else
            {
                var testResult = SpecificationRunner.RunTest(this._testContext, new List<string>());

                NativeTestResult.ApplyToNunitResult(testResult, nunitTestResult);
            }

            listener.TestFinished(nunitTestResult);

            return nunitTestResult;
        }
Exemplo n.º 16
0
        public void TestFinished(TestResult testResult)
        {
            switch (testResult.ResultState)
            {
                case ResultState.Error:
                case ResultState.Failure:
                case ResultState.Cancelled:
                    var result = new AutoTest.TestRunners.Shared.Results.TestResult("NUnit", currentAssembly, getFixture(testResult.Test.TestName.FullName), testResult.Time * 1000, testResult.Test.TestName.FullName, TestRunners.Shared.Results.TestState.Failed, testResult.Message);
                    result.AddStackLines(getStackLines(testResult).ToArray());
                    _results.Add(result);
                    break;

                case ResultState.Success:
                    _results.Add(new AutoTest.TestRunners.Shared.Results.TestResult("NUnit", currentAssembly, getFixture(testResult.Test.TestName.FullName), testResult.Time * 1000, testResult.Test.TestName.FullName, TestRunners.Shared.Results.TestState.Passed, testResult.Message));
                    break;

                case ResultState.Inconclusive:
                case ResultState.Ignored:
                case ResultState.Skipped:
                case ResultState.NotRunnable:
                    var ignoreResult = new AutoTest.TestRunners.Shared.Results.TestResult("NUnit", currentAssembly, getFixture(testResult.Test.TestName.FullName), testResult.Time * 1000, testResult.Test.TestName.FullName, TestRunners.Shared.Results.TestState.Ignored, testResult.Message);
                    ignoreResult.AddStackLines(getStackLines(testResult).ToArray());
                    _results.Add(ignoreResult);
                    break;
            }
        }
Exemplo n.º 17
0
        public VSTestResult ConvertTestResult(NUnitTestResult result)
        {
            TestCase ourCase = GetCachedTestCase(result.Test.TestName.UniqueName);
            if (ourCase == null) return null;

            VSTestResult ourResult = new VSTestResult(ourCase)
                {
                    DisplayName = ourCase.DisplayName,
                    Outcome = ResultStateToTestOutcome(result.ResultState),
                    Duration = TimeSpan.FromSeconds(result.Time)
                };

            // TODO: Remove this when NUnit provides a better duration
            if (ourResult.Duration == TimeSpan.Zero && (ourResult.Outcome == TestOutcome.Passed || ourResult.Outcome == TestOutcome.Failed))
                ourResult.Duration = TimeSpan.FromTicks(1);
            ourResult.ComputerName = Environment.MachineName;

            // TODO: Stuff we don't yet set
            //   StartTime   - not in NUnit result
            //   EndTime     - not in NUnit result
            //   Messages    - could we add messages other than the error message? Where would they appear?
            //   Attachments - don't exist in NUnit

            if (result.Message != null)
                ourResult.ErrorMessage = GetErrorMessage(result);

            if (!string.IsNullOrEmpty(result.StackTrace))
            {
                string stackTrace = StackTraceFilter.Filter(result.StackTrace);
                ourResult.ErrorStackTrace = stackTrace;
            }

            return ourResult;
        }
 public void TestFinished(TestResult result)
 {
     if (ConfigReader.DefaultProvider.AllConfiguration.NUnitAddin.ReportBack)
     {
         Communicator.ReportResultToSpiraTeam(result);
     }
 }
        public XmlResultVisitor( TextWriter writer, TestResult result )
		{
			this.memoryStream = new MemoryStream();
			this.writer = writer;
			this.xmlWriter = new XmlTextWriter( new StreamWriter( memoryStream, System.Text.Encoding.UTF8 ) );
			Initialize( result );
		}
        public new void SuiteFinished(TestResult suiteResult)
        {
            if ( --level == 0)
            {
                Trace.WriteLine( "############################################################################" );

                if (messages.Count == 0)
                {
                    Trace.WriteLine( "##############                 S U C C E S S               #################" );
                }
                else
                {
                    Trace.WriteLine( "##############                F A I L U R E S              #################" );

                    foreach ( string s in messages )
                    {
                        Trace.WriteLine(s);
                    }
                }

                Trace.WriteLine( "############################################################################" );
                Trace.WriteLine( "Executed tests       : " + testRunCount );
                Trace.WriteLine( "Ignored tests        : " + testIgnoreCount );
                Trace.WriteLine( "Failed tests         : " + failureCount );
                Trace.WriteLine( "Unhandled exceptions : " + unhandledExceptions.Count);
                Trace.WriteLine( "Total time           : " + suiteResult.Time + " seconds" );
                Trace.WriteLine( "############################################################################");
            }
        }
        public override void DoFixtureSetUp(TestResult suiteResult)
        {
            try
            {
                _fixture.FixtureSetup();

                Status = SetUpState.SetUpComplete;
            }
            catch (Exception ex)
            {
                if (ex is NunitException || ex is TargetInvocationException)
                    ex = ex.InnerException;

                if (testFramework.IsIgnoreException(ex))
                {
                    ShouldRun = false;
                    suiteResult.NotRun(ex.Message);
                    suiteResult.StackTrace = ex.StackTrace;
                    IgnoreReason = ex.Message;
                }
                else
                {
                    suiteResult.Failure(ex.Message, ex.StackTrace);
                    Status = SetUpState.SetUpFailed;
                }
            }
            finally
            {
                if (testFramework != null)
                    suiteResult.AssertCount = testFramework.GetAssertCount();
            }
        }
Exemplo n.º 22
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            listener.TestStarted(base.TestName);
            long ticks = DateTime.Now.Ticks;
            var testResult = new TestResultShim();

            Exception existingError = null;

            _globalSetup.PrepareForTestPosition(Position, out existingError);

            if (existingError != null)
            {
                TestResultUtil.Error(testResult, TestExtensions.GetMultilineName(this), existingError, null, TestResultShim.Site.SetUp);
            }
            else
            {
                List<string> traceMessages = null;
                try
                {
                    RunTestMethod(testResult, out traceMessages);
                }
                catch (Exception e)
                {
                    var globalTraceMessages = _globalSetup.GetTraceMessages();
                    TestResultUtil.Error(testResult, TestExtensions.GetMultilineName(this), e, globalTraceMessages.Concat(traceMessages));
                }
            }

            var nunitTestResult = new TestResult(this);
            NativeTestResult.ApplyToNunitResult(testResult, nunitTestResult);
            nunitTestResult.Time = ((DateTime.Now.Ticks - ticks)) / 10000000.0;
            listener.TestFinished(nunitTestResult);
            return nunitTestResult;
        }
Exemplo n.º 23
0
        // ----------------------------------------------------------------------
        private void AppendResult( TestResult testResult )
        {
            if ( testResult.IsSuccess )
            {
                return;
            }

            if ( testResult.Results == null )
            {
                if ( testResult.IsFailure )
                {
                    failedTests.Add( string.Format( "{0}: {1}", testResult.FullName, testResult.Message ) );
                    if ( !string.IsNullOrEmpty( testResult.StackTrace ) )
                    {
                        failedTests.Add( testResult.StackTrace );
                    }
                }
                if ( testResult.IsError )
                {
                    errorTests.Add( string.Format( "{0}: {1}", testResult.FullName, testResult.Message ) );
                    if ( !string.IsNullOrEmpty( testResult.StackTrace ) )
                    {
                        errorTests.Add( testResult.StackTrace );
                    }
                }
            }
            else
            {
                foreach ( TestResult childResult in testResult.Results )
                {
                    AppendResult( childResult );
                }
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Saves the TestResult as xml to the specified path.
 /// </summary>
 /// <param name="result">The test result to be saved.</param>
 /// <param name="outputXmlPath">The output xml path.</param>
 private static void SaveXmlOutput(TestResult result, string outputXmlPath)
 {
     if (!string.IsNullOrEmpty(outputXmlPath))
     {
         var writer = new XmlResultWriter(outputXmlPath);
         writer.SaveTestResult(result);
     }
 }
Exemplo n.º 25
0
 public void RunFinished(TestResult testResult)
 {
     var dialog = new TestReportDialog(_nrOk, _nrFailed, _resultsAL);
       TestReportDialog.ShowHelpButton(false);
       dialog.ShowAll();
       dialog.Run();
       dialog.Destroy();
 }
Exemplo n.º 26
0
        private void AddNode( TestResult result )
        {
            TreeNode node = new TreeNode(result.Name);
            TreeNode reasonNode = new TreeNode("Reason: " + result.Message);
            node.Nodes.Add(reasonNode);

            Nodes.Add( node );
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates an instance of TestResultViewerViewModel.
        /// </summary>
        /// <param name="rootResult">The root of test result object.</param>
        public TestResultViewerViewModel(TestResult rootResult, string resultFile)
        {
            TestResults = new ObservableCollection<TestItemViewModel>();

             ResultFileName = resultFile;

             WalkTheTestResult(rootResult);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Saves the TestResult as xml to the specified path.
 /// </summary>
 /// <param name="result">The test result to be saved.</param>
 /// <param name="textWriter">The text writer.</param>
 public static void SaveXmlOutput(TestResult result, TextWriter textWriter)
 {
     if (textWriter != null)
     {
         var writer = new XmlResultWriter(textWriter);
         writer.SaveTestResult(result);
     }
 }
Exemplo n.º 29
0
        public void DisplayResults( TestResult results )
        {
            notRunTree.BeginUpdate();
            results.Accept(this);
            notRunTree.EndUpdate();

            if( testDetails.Items.Count > 0 )
                testDetails.SelectedIndex = 0;
        }
Exemplo n.º 30
0
 public void RunFinished(TestResult result)
 {
     Console.WriteLine("\nNumber of tests: "+count+"  Failed: "+failed+"  Skipped: "+skipped);
     if(result.IsSuccess) {
         Console.WriteLine("ALL OK");
     } else {
         Console.WriteLine("TESTRUN FAILED: "+result.Message);
     }
 }
Exemplo n.º 31
0
        public void RunFinished(NUnit.Core.TestResult testResult)
        {
            this.testResult = testResult;

            try
            {
                this.SaveLastResult(
                    Path.Combine(Path.GetDirectoryName(this.TestFileName), "TestResult.xml"));
                events.FireRunFinished(testResult);
            }
            catch (Exception ex)
            {
                this.lastException = ex;
                events.FireRunFinished(ex);
            }
        }
Exemplo n.º 32
0
        public void TestFinished(NUnit.Core.TestResult testResult)
        {
            ++this.s.TestCount;
            switch (testResult.ResultState)
            {
            case ResultState.Inconclusive:
                ++this.s.InconclusiveCount;
                break;

            case ResultState.Success:
                ++this.s.PassCount;
                break;

            case ResultState.NotRunnable:
                ++this.s.InvalidCount;
                break;

            case ResultState.Skipped:
                ++this.s.SkipCount;
                break;

            case ResultState.Ignored:
                ++this.s.IgnoreCount;
                break;

            case ResultState.Failure:
                ++this.s.FailureCount;
                FormatStackTrace(testResult);
                break;

            case ResultState.Error:
                ++this.s.ErrorCount;
                FormatStackTrace(testResult);
                break;

            case ResultState.Cancelled:
                ++this.s.FailureCount;
                FormatStackTrace(testResult);
                break;
            }
            if (this._messageSubscribeAdapter != null)
            {
                this._messageSubscribeAdapter.TestFinished(testResult);
            }
            this.currentTestName = string.Empty;
        }
Exemplo n.º 33
0
        private void FormatStackTrace(NUnit.Core.TestResult testResult)
        {
            this.outWriter.WriteLine(string.Format("{0}) {1} :", this.s.FailureCount, testResult.Test.TestName.FullName));
            this.outWriter.WriteLine(testResult.Message.Trim(Environment.NewLine.ToCharArray()));
            string filteredStackTrace = StackTraceFilter.Filter(testResult.StackTrace);

            if (filteredStackTrace != null && filteredStackTrace != string.Empty)
            {
                foreach (string stackTraceLines in filteredStackTrace.Split(Environment.NewLine.ToCharArray()))
                {
                    if (stackTraceLines != string.Empty)
                    {
                        this.outWriter.WriteLine(string.Format("at\n{0}",
                                                               Regex.Replace(stackTraceLines.Trim(), ".* in (.*):line (.*)", "$1($2)")));
                    }
                }
            }
        }
        public void SetUp()
        {
            MethodInfo fakeTestMethod = GetType().GetMethod("FakeTestMethod", BindingFlags.Instance | BindingFlags.NonPublic);

            fakeNUnitTest = new NUnitTestMethod(fakeTestMethod);

            fakeNUnitResult = new NUnitTestResult(fakeNUnitTest);
            fakeNUnitResult.SetResult(ResultState.Success, "It passed!", null);
            fakeNUnitResult.Time = 1.234;

            testLog = new FakeFrameworkHandle();

            testConverter = new TestConverter(new TestLogger(), ThisAssemblyPath);

            testConverter.ConvertTestCase(fakeNUnitTest);
            Assert.NotNull(testConverter.GetCachedTestCase(fakeNUnitTest.TestName.UniqueName));

            listener = new NUnitEventListener(testLog, testConverter);
        }
Exemplo n.º 35
0
        public VSTestResult ConvertTestResult(NUnitTestResult result)
        {
            TestCase ourCase = GetCachedTestCase(result.Test.TestName.UniqueName);

            if (ourCase == null)
            {
                return(null);
            }

            VSTestResult ourResult = new VSTestResult(ourCase)
            {
                DisplayName = ourCase.DisplayName,
                Outcome     = ResultStateToTestOutcome(result.ResultState),
                Duration    = TimeSpan.FromSeconds(result.Time)
            };

            // TODO: Remove this when NUnit provides a better duration
            if (ourResult.Duration == TimeSpan.Zero && (ourResult.Outcome == TestOutcome.Passed || ourResult.Outcome == TestOutcome.Failed))
            {
                ourResult.Duration = TimeSpan.FromTicks(1);
            }
            ourResult.ComputerName = Environment.MachineName;

            // TODO: Stuff we don't yet set
            //   StartTime   - not in NUnit result
            //   EndTime     - not in NUnit result
            //   Messages    - could we add messages other than the error message? Where would they appear?
            //   Attachments - don't exist in NUnit

            if (result.Message != null)
            {
                ourResult.ErrorMessage = GetErrorMessage(result);
            }

            if (!string.IsNullOrEmpty(result.StackTrace))
            {
                string stackTrace = StackTraceFilter.Filter(result.StackTrace);
                ourResult.ErrorStackTrace = stackTrace;
            }

            return(ourResult);
        }
Exemplo n.º 36
0
            public void TestFinished(TestCaseResult testResult)
            {
                if (testResult.Executed)
                {
                    testRunCount++;

                    if (testResult.IsFailure)
                    {
                        failureCount++;
                        Console.Write("F");
                        if (debugger)
                        {
#if NUNIT_2_5
                            messages.Add(string.Format("{0}) {1} :", failureCount, testResult.Test.TestName.FullName));
#else
                            messages.Add(string.Format("{0}) {1} :", failureCount, testResult.Test.FullName));
#endif
                            messages.Add(testResult.Message.Trim(Environment.NewLine.ToCharArray()));

                            string   stackTrace = StackTraceFilter.Filter(testResult.StackTrace);
                            string[] trace      = stackTrace.Split(System.Environment.NewLine.ToCharArray());
                            foreach (string s in trace)
                            {
                                if (s != string.Empty)
                                {
                                    string link = Regex.Replace(s.Trim(), @".* in (.*):line (.*)", "$1($2)");
                                    messages.Add(string.Format("at\n{0}", link));
                                }
                            }
                        }
                    }
                }
                else
                {
                    testIgnoreCount++;
                    Console.Write("N");
                }


                currentTestName = string.Empty;
            }
Exemplo n.º 37
0
        public void CanMakeTestResultFromNUnitTestResult()
        {
            // This should put the TestCase in the cache
            var cachedTestCase = testConverter.ConvertTestCase(fakeNUnitTest);

            var nunitResult = new NUnitTestResult(fakeNUnitTest);

            nunitResult.SetResult(ResultState.Success, "It passed!", null);
            nunitResult.Time = 1.234;

            var testResult = testConverter.ConvertTestResult(nunitResult);
            var testCase   = testResult.TestCase;

            Assert.That(testCase, Is.SameAs(cachedTestCase));

            CheckTestCase(testCase);

            Assert.That(testResult.Outcome, Is.EqualTo(TestOutcome.Passed));
            Assert.That(testResult.ErrorMessage, Is.EqualTo("It passed!"));
            Assert.That(testResult.Duration, Is.EqualTo(TimeSpan.FromSeconds(1.234)));
        }
Exemplo n.º 38
0
        private void GetTestResult(NUnit.Core.TestResult result, ref TestRail.TestResult tc, ref string failureTestCases)
        {
            string[] featuretags = FeatureContext.Current.FeatureInfo.Tags;
            string[] tagstr      = ScenarioContext.Current.ScenarioInfo.Tags;
            if (result.ResultState == ResultState.Ignored)
            {
                return;
            }
            string result_status     = string.Empty;
            string result_message    = string.Empty;
            string result_stackTrace = string.Empty;

            tc = new TestRail.TestResult();
            foreach (string str in tagstr)
            {
                string tagname  = str.Split(':')[0].ToUpper();
                string tagvalue = str.Substring(str.IndexOf(str.Split(':')[1]));
                switch (tagname)
                {
                case "CASEID": tc.Case_id = tagvalue; break;

                case "PRIORITY": tc.Priority = tagvalue; break;

                case "MILESTONE": tc.MileStone = tagvalue; break;

                case "TYPE": tc.Type = tagvalue; break;
                    // case "SUITENAME": tc.Suite_Name = tagvalue; break;
                }
            }
            tc.Suite_Id = tru.GetSuiteIdByCaseId(tc.Case_id);


            tc.Result_status  = result.ResultState.ToString();
            tc.Result_message = output;
            if (!result.IsSuccess)
            {
                //log failure test cases
                failureTestCases += "caseid:" + tc.Case_id + ",";
            }
        }
Exemplo n.º 39
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());
        }
Exemplo n.º 40
0
        protected override void DoOneTimeTearDown(TestResult suiteResult)
        {
            base.DoOneTimeTearDown(suiteResult);

            suiteResult.AssertCount += NUnitFramework.GetAssertCount();
        }
Exemplo n.º 41
0
 public void TestFinished(NUnit.Core.TestResult result)
 {
     testRunnerEventListener.TestFinished(result.UnitTestResult());
 }
Exemplo n.º 42
0
 public void SuiteFinished(NUnit.Core.TestResult result)
 {
 }
Exemplo n.º 43
0
 public void TestFinished(NUnit.Core.TestResult result)
 {
     m_TestRunnerEventListener.TestFinished(result.UnitTestResult(m_testLog.ToString()));
     m_testLog = null;
 }
Exemplo n.º 44
0
 public void RunFinished(NUnit.Core.TestResult result)
 {
     testRunnerEventListener.RunFinished();
 }
Exemplo n.º 45
0
 public virtual void DoSetUp(TestResult suiteResult)
 {
 }
 public void BeginRun(EventListener listener, ITestFilter filter, bool tracing, LoggingThreshold logLevel)
 {
     testResult = this.Run(listener, filter, tracing, logLevel);
 }
Exemplo n.º 47
0
        public void TestFinished(NUnit.Core.TestResult result)
        {
            TestRail.TestResult tr = null;
            string testType        = result.Test.TestType;


            try
            {
                GetTestResult(result, ref tr, ref failureTestCases);
                //update automation type to  specflow after test finished
                TestRail.Case cse = tru.GetCaseByCaseId(tr.Case_id);
                if (cse.AutomationType != "4")
                {
                    tru.UpdateAutomationTypeToSpecFlow(tr.Case_id);
                }

                suiteid = tr.Suite_Id;
                if (result.Test.Categories.Count == 0)
                {
                    if (result.IsSuccess)
                    {
                        testcaseres.Add(true);
                    }
                    else
                    {
                        testcaseres.Add(false);
                    }
                    results.Add(result.FullName, tr.Result_status.ToString());
                    caseid = tr.Case_id;
                }

                if (!result.IsSuccess)
                {
                    AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_FailureTestCases.log"), result.FullName);
                }

                List <Run> runs = tru.GetRunIdsByProjectNameAndPlanNameAndSuiteId(project, planName, tr.Suite_Id);

                // List<string> runids = GetTestRunsByPlanNameAndSuiteId(project, planName, tr.Suite_Id, tr.Case_id);

                #region
                //if (runname.Trim() == string.Empty)
                //{
                //    foreach (Run run in runs)
                //    {
                //        TestRail.Suite suite = null;
                //        TestRail.Case cs = null;
                //        TestRail.LocalTestCase ltc = null;
                //        output = string.Empty;
                //        tr.RunId = run.Id;
                //        if (bAddTestResult)
                //        {
                //            tru.AddTestResult(tr);
                //        }
                //        if (btestCaseSync && result.Test.Categories.Count == 1)
                //        {
                //            bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite);
                //            if (updateresult)
                //            {

                //                string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title;
                //                AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message);
                //            }
                //        }
                //    }
                //}
                //else
                //{
                //    foreach (Run run in runs)
                //    {
                //        if (run.RunName == runname.Trim())
                //        {
                //            TestRail.Suite suite = null;
                //            TestRail.Case cs = null;
                //            TestRail.LocalTestCase ltc = null;
                //            output = string.Empty;
                //            tr.RunId = run.Id;
                //            if (bAddTestResult)
                //            {
                //                tru.AddTestResult(tr);
                //            }
                //            if (btestCaseSync && result.Test.Categories.Count == 1)
                //            {
                //                bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite);
                //                if (updateresult)
                //                {

                //                    string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title;
                //                    AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message);
                //                }
                //            }
                //        }
                //    }
                //}
                #endregion

                foreach (Run run in runs)
                {
                    if (runname.Trim() == string.Empty)
                    {
                        TestRail.Suite         suite = null;
                        TestRail.Case          cs    = null;
                        TestRail.LocalTestCase ltc   = null;
                        output   = string.Empty;
                        tr.RunId = run.Id;
                        if (bAddTestResult)
                        {
                            tru.AddTestResult(tr);
                        }
                        if (btestCaseSync && result.Test.Categories.Count == 1)
                        {
                            bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite);
                            if (updateresult)
                            {
                                string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title;
                                AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message);
                            }
                        }
                    }
                    else
                    {
                        if (run.RunName == runname.Trim())
                        {
                            TestRail.Suite         suite = null;
                            TestRail.Case          cs    = null;
                            TestRail.LocalTestCase ltc   = null;
                            output   = string.Empty;
                            tr.RunId = run.Id;
                            if (bAddTestResult)
                            {
                                tru.AddTestResult(tr);
                            }
                            if (btestCaseSync && result.Test.Categories.Count == 1)
                            {
                                bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite);
                                if (updateresult)
                                {
                                    string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title;
                                    AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                caseid = tr.Case_id;
                string errorMsg = result.FullName + ":\r\n" + "caseid:" + caseid + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n";
                AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_ErrorMsg.log"), errorMsg);
                throw ex;
            }
        }
Exemplo n.º 48
0
 public void SuiteFinished(TestResult result)
 {
 }
Exemplo n.º 49
0
 public virtual void DoTearDown(TestResult suiteResult)
 {
 }
Exemplo n.º 50
0
        public void SuiteFinished(NUnit.Core.TestResult result)
        {
            string testType = result.Test.TestType;

            if (testType == "ParameterizedTest")
            {
                finalres = testcaseres[0];

                foreach (bool res in testcaseres)
                {
                    finalres &= res;
                }
                TestRail.TestResult tr = new TestRail.TestResult();
                tr.Case_id = caseid;
                if (finalres)
                {
                    tr.Result_status  = "Success";
                    tr.Result_message = "Final result -Success: \r\n";
                }
                else
                {
                    tr.Result_status  = "Failure";
                    tr.Result_message = "Final result -Failure: \r\n";
                }
                foreach (KeyValuePair <string, string> res in results)
                {
                    tr.Result_message += res.Key + ":" + res.Value + "\r\n";
                }

                try
                {
                    // List<string> runids = GetTestRunsByPlanNameAndSuiteId(project, planName, suiteid, tr.Case_id);
                    List <Run> runs = tru.GetRunIdsByProjectNameAndPlanNameAndSuiteId(project, planName, suiteid);
                    foreach (Run run in runs)
                    {
                        if (runname.Trim() == string.Empty)
                        {
                            tr.RunId = run.Id;
                            if (bAddTestResult)
                            {
                                tru.AddTestResult(tr);
                            }
                            if (btestCaseSync)
                            {
                                TestRail.Suite         suite = null;
                                TestRail.Case          cs    = null;
                                TestRail.LocalTestCase ltc   = null;
                                bool updateresult            = SyncTestcase(tr, ref ltc, ref cs, ref suite);
                                if (updateresult)
                                {
                                    string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title;
                                    AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message);
                                }
                            }
                        }
                        else
                        {
                            if (run.RunName == runname.Trim())
                            {
                                tr.RunId = run.Id;
                                if (bAddTestResult)
                                {
                                    tru.AddTestResult(tr);
                                }
                                if (btestCaseSync)
                                {
                                    TestRail.Suite         suite = null;
                                    TestRail.Case          cs    = null;
                                    TestRail.LocalTestCase ltc   = null;
                                    bool updateresult            = SyncTestcase(tr, ref ltc, ref cs, ref suite);
                                    if (updateresult)
                                    {
                                        string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title;
                                        AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    caseid = tr.Case_id;
                    string errorMsg = result.FullName + ":\r\n" + "caseid:" + caseid + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n";
                    AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_ErrorMsg.log"), errorMsg);
                    throw ex;
                }
            }
            results.Clear();
            testcaseres.Clear();
        }
Exemplo n.º 51
0
 void EventListener.TestFinished(NUnit.Core.TestResult result)
 {
     OnTestFinished(new TestSummary {
         Result = result.ResultState.ToTestResult()
     });
 }
Exemplo n.º 52
0
 private void UpdateTestResults(NUnit.Core.TestResult result)
 {
     ToUnitTestResult(result);
 }
Exemplo n.º 53
0
 public void RunFinished(NUnit.Core.TestResult result)
 {
     OnTestRunFinished(new TestSummary {
         Result = result.ResultState.ToTestResult()
     });
 }
Exemplo n.º 54
0
        protected override void DoOneTimeSetUp(TestResult suiteResult)
        {
            base.DoOneTimeSetUp(suiteResult);

            suiteResult.AssertCount = NUnitFramework.GetAssertCount();;
        }
Exemplo n.º 55
0
        public void RunFinished(NUnit.Core.TestResult testResult)
        {
            this.testResult = testResult;

            events.FireRunFinished(testResult);
        }