コード例 #1
0
        /// <summary>
        /// Process a result.
        /// </summary>
        /// <param name="result">The result data.</param>
        private void ProcessResult(ScenarioResult result)
        {
            TestClassData  tac = GetClassModel(result.TestClass);
            TestMethodData tmd = GetMethodModel(result.TestMethod, tac);

            tmd.IsRunning = false;

            tmd.IsNotable = !tmd.Passed;

            if (_d == null)
            {
                return;
            }

            // Link to previous
            tmd.PreviousResult = _lastResult;
            _lastResult        = tmd;

            _d.RunScenarios++;
            if (result.Result != TestOutcome.Passed)
            {
                _d.FailedScenarios++;

                // Link to previous failure
                tmd.PreviousFailingResult = _lastFailingResult;
                _lastFailingResult        = tmd;

                // Automatically check the item for the user
                tmd.IsChecked = true;
            }

            tmd.Result = result;
        }
コード例 #2
0
        /// <summary>
        /// Process the start of a test method.
        /// </summary>
        /// <param name="sender">The source object.</param>
        /// <param name="e">The event data.</param>
        private void OnTestMethodStarting(object sender, TestMethodStartingEventArgs e)
        {
            TestClassData  tac = GetClassModel(e.TestClass);
            TestMethodData tmd = GetMethodModel(e.TestMethod, tac);

            if (!tac.IsExpanded)
            {
                tac.IsExpanded = true;
            }
            tmd.IsRunning = true;

            _d.CurrentTestMethod = e.TestMethod.Name;
        }
コード例 #3
0
        /// <summary>
        /// Gets or creates the data model object for a test method.
        /// </summary>
        /// <param name="testMethod">The test method.</param>
        /// <param name="parentTestClass">The parent test class data object.</param>
        /// <returns>Returns the data object.</returns>
        public TestMethodData GetMethodModel(ITestMethod testMethod, TestClassData parentTestClass)
        {
            TestMethodData data;

            if (!_methodData.TryGetValue(testMethod, out data))
            {
                data = new TestMethodData(testMethod, parentTestClass);
                _methodData.Add(testMethod, data);

                // Make sure in parent collection
                parentTestClass.TestMethods.Add(data);
            }

            return(data);
        }
コード例 #4
0
ファイル: DataManager.cs プロジェクト: fstn/WindowsPhoneApps
        /// <summary>
        /// Gets or creates the data model object for a test method.
        /// </summary>
        /// <param name="testMethod">The test method.</param>
        /// <param name="parentTestClass">The parent test class data object.</param>
        /// <returns>Returns the data object.</returns>
        public TestMethodData GetMethodModel(ITestMethod testMethod, TestClassData parentTestClass)
        {
            TestMethodData data;
            if (!_methodData.TryGetValue(testMethod, out data))
            {
                data = new TestMethodData(testMethod, parentTestClass);
                _methodData.Add(testMethod, data);

                // Make sure in parent collection
                parentTestClass.TestMethods.Add(data);
            }

            return data;
        }
コード例 #5
0
ファイル: DataManager.cs プロジェクト: fstn/WindowsPhoneApps
        /// <summary>
        /// Process a result.
        /// </summary>
        /// <param name="result">The result data.</param>
        private void ProcessResult(ScenarioResult result)
        {
            TestClassData tac = GetClassModel(result.TestClass);
            TestMethodData tmd = GetMethodModel(result.TestMethod, tac);

            tmd.IsRunning = false;

            tmd.IsNotable = !tmd.Passed;

            if (_d == null)
            {
                return;
            }

            // Link to previous
            tmd.PreviousResult = _lastResult;
            _lastResult = tmd;

            _d.RunScenarios++;
            if (result.Result != TestOutcome.Passed)
            {
                _d.FailedScenarios++;

                // Link to previous failure
                tmd.PreviousFailingResult = _lastFailingResult;
                _lastFailingResult = tmd;

                // Automatically check the item for the user
                tmd.IsChecked = true;
            }

            tmd.Result = result;
        }
コード例 #6
0
        /// <summary>
        /// Formats the test method data into a string.
        /// </summary>
        /// <param name="methodData">The test method data</param>
        /// <returns>A string representing the test method data.</returns>
        private string MethodDetailToString(TestMethodData methodData)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendFormat("    {0}", methodData.Description);
            sb.AppendLine();
            sb.AppendFormat("    Result: {0}", methodData.Result.Result);
            sb.AppendLine();
            sb.AppendLine("    Executing Time");
            sb.AppendFormat("    Started: {0}", methodData.Result.Started);
            sb.AppendLine();
            sb.AppendFormat("    Finished: {0}", methodData.Result.Finished);
            sb.AppendLine();
            sb.AppendFormat("    Elapsed Time: {0}", methodData.ReadableElapsedTime);
            sb.AppendLine();
            sb.AppendLine();
            if (methodData.KnownBugs != null)
            {
                sb.AppendLine("    ...");
                sb.AppendLine("    Known Issues");
                sb.AppendLine("    ...");
                if (methodData.Passed)
                {
                    sb.AppendLine("    These issues are marked as known for this test and resulted in it being marked as a success:");
                }
                else
                {
                    sb.AppendLine("    These known issues should be marked fixed.");
                    sb.AppendLine("    The test passed otherwise.");
                }
                foreach (string bug in methodData.KnownBugs)
                {
                    sb.AppendLine("    * " + bug);
                }
            }

            if (methodData.FixedBugs != null)
            {
                sb.AppendLine("    ...");
                sb.AppendLine("    Fixed Issues");
                sb.AppendLine("    ...");
                if (!methodData.Passed)
                {
                    sb.AppendLine("    These issues were marked as fixed, but should still be investigated for this failing test:");
                }
                foreach (string bug in methodData.FixedBugs)
                {
                    sb.AppendLine("    * " + bug);
                }
            }

            if (!string.IsNullOrEmpty(methodData.SimplifiedExpectedExceptionName))
            {
                sb.AppendLine("    ...");
                sb.AppendLine("    Expected Exception (Negative Test)");
                sb.AppendLine("    ...");
                sb.AppendLine("    This test expected an exception of type");
                sb.AppendLine("    " + methodData.SimplifiedExpectedExceptionName);
            }

            if (methodData.Result.Exception != null)
            {
                sb.AppendLine("    ...");
                sb.AppendLine("    Exception Details");
                sb.AppendLine("    ...");
                sb.AppendFormat("    {0}  was unhandled", methodData.SimplifiedExceptionName);
                sb.AppendLine();
                sb.AppendLine("    " + methodData.Result.Exception.Message);
                sb.AppendLine(methodData.SimplifiedExceptionStackTrace);

                if (methodData.Result.Exception.InnerException != null)
                {
                    sb.AppendLine("    This test result also contained an inner exception:");
                    sb.AppendFormat("    {0}", methodData.Result.Exception.InnerException);
                    sb.AppendLine();
                }
            }
            return(sb.ToString());
        }
コード例 #7
0
        /// <summary>
        /// Collects the test results on a string representation.
        /// </summary>
        /// <param name="recursive">Indicates if the results are gathered with
        /// details.</param>
        /// <returns>A string containing the result text.</returns>
        private TestResultPlainData CollectContextResults(bool recursive)
        {
            string        results  = string.Empty;
            string        fileName = string.Empty;
            StringBuilder sb       = new StringBuilder();

            DateTime currentDate = DateTime.Now;

            sb.AppendLine("Windows Phone Test Framework");
            sb.AppendLine("=====================");
            sb.AppendLine("Test Data");
            sb.AppendLine("=====================");

            // Main Result view is visible (full results)
            if (TestExecution.Visibility == Visibility.Visible)
            {
                fileName = String.Format("Test.{0}.txt", currentDate.ToString("yyyy.mm.dd.HH.MM.ss"));

                foreach (TestAssemblyData tAssembly in _model.Data.TestAssemblies)
                {
                    sb.AppendLine("Assembly Name:");
                    sb.AppendLine(tAssembly.Name);
                    sb.AppendFormat("{0} passed methods, {1} failed methods", tAssembly.PassCount, tAssembly.FailCount);
                    sb.AppendLine();
                    sb.AppendLine("***");

                    foreach (TestClassData tClass in tAssembly.TestClasses)
                    {
                        sb.AppendLine("  Class Name:");
                        sb.AppendLine("  " + tClass.Name);
                        sb.AppendFormat("  {0} passed methods, {1} failed methods", tClass.PassCount, tClass.FailCount);
                        sb.AppendLine();
                        sb.AppendLine("  ---");
                        foreach (TestMethodData tMethod in tClass.TestMethods)
                        {
                            sb.AppendFormat("    [{0}] {1}", tMethod.Passed ? "PASS" : "FAIL", tMethod.Name);
                            if (recursive)
                            {
                                sb.Append(MethodDetailToString(tMethod));
                                sb.AppendLine("    +++");
                            }
                            sb.AppendLine();
                        }
                        sb.AppendLine("  ###");
                    }
                }
                results = sb.ToString();
            }
            else
            {
                // Method details view is visible.
                if (TestMethodView.Visibility == Visibility.Visible)
                {
                    if (TestMethodView.Children.Count == 1)
                    {
                        TestMethodData tMethod = (TestMethodView.Children[0] as TestMethodDetails).DataContext as TestMethodData;
                        fileName = String.Format("{0}.{1}.{2}.{3}.txt", tMethod.Parent.Namespace, tMethod.Parent.Name, tMethod.Name, currentDate.ToString("yyyy.mm.dd.HH.MM.ss"));

                        sb.AppendLine("Assembly Name:");
                        sb.AppendLine(tMethod.Parent.Parent.Name);
                        sb.AppendLine("***");
                        sb.AppendLine("Class Name:");
                        sb.AppendLine(tMethod.Parent.Name);
                        sb.AppendLine("Method Name:");
                        sb.AppendLine(tMethod.Name);
                        sb.Append(MethodDetailToString(tMethod));

                        results = sb.ToString();
                    }
                }
            }
            return(new TestResultPlainData {
                FileName = fileName, Text = results
            });
        }
コード例 #8
0
    /// <summary>
    /// Formats the test method data into a string.
    /// </summary>
    /// <param name="methodData">The test method data</param>
    /// <returns>A string representing the test method data.</returns>
    private string MethodDetailToString(TestMethodData methodData)
    {
      StringBuilder sb = new StringBuilder();
      sb.AppendLine();
      sb.AppendFormat("    {0}", methodData.Description);
      sb.AppendLine();
      sb.AppendFormat("    Result: {0}", methodData.Result.Result);
      sb.AppendLine();
      sb.AppendLine("    Executing Time");
      sb.AppendFormat("    Started: {0}", methodData.Result.Started);
      sb.AppendLine();
      sb.AppendFormat("    Finished: {0}", methodData.Result.Finished);
      sb.AppendLine();
      sb.AppendFormat("    Elapsed Time: {0}", methodData.ReadableElapsedTime);
      sb.AppendLine();
      sb.AppendLine();
      if (methodData.KnownBugs != null)
      {
        sb.AppendLine("    ...");
        sb.AppendLine("    Known Issues");
        sb.AppendLine("    ...");
        if (methodData.Passed)
        {
          sb.AppendLine("    These issues are marked as known for this test and resulted in it being marked as a success:");
        }
        else
        {
          sb.AppendLine("    These known issues should be marked fixed.");
          sb.AppendLine("    The test passed otherwise.");
        }
        foreach (string bug in methodData.KnownBugs)
        {
          sb.AppendLine("    * " + bug);
        }
      }

      if (methodData.FixedBugs != null)
      {
        sb.AppendLine("    ...");
        sb.AppendLine("    Fixed Issues");
        sb.AppendLine("    ...");
        if (!methodData.Passed)
        {
          sb.AppendLine("    These issues were marked as fixed, but should still be investigated for this failing test:");
        }
        foreach (string bug in methodData.FixedBugs)
        {
          sb.AppendLine("    * " + bug);
        }
      }

      if (!string.IsNullOrEmpty(methodData.SimplifiedExpectedExceptionName))
      {
        sb.AppendLine("    ...");
        sb.AppendLine("    Expected Exception (Negative Test)");
        sb.AppendLine("    ...");
        sb.AppendLine("    This test expected an exception of type");
        sb.AppendLine("    " + methodData.SimplifiedExpectedExceptionName);
      }

      if (methodData.Result.Exception != null)
      {
        sb.AppendLine("    ...");
        sb.AppendLine("    Exception Details");
        sb.AppendLine("    ...");
        sb.AppendFormat("    {0}  was unhandled", methodData.SimplifiedExceptionName);
        sb.AppendLine();
        sb.AppendLine("    " + methodData.Result.Exception.Message);
        sb.AppendLine(methodData.SimplifiedExceptionStackTrace);

        if (methodData.Result.Exception.InnerException != null)
        {
          sb.AppendLine("    This test result also contained an inner exception:");
          sb.AppendFormat("    {0}", methodData.Result.Exception.InnerException);
          sb.AppendLine();
        }
      }
      return sb.ToString();
    }