コード例 #1
0
        public static TestResult FindTestResult(string name, TestResult result)
        {
            if (result == null) return null;

            if (result.Name.ToLower() == name.ToLower()) return result;

            if (result.IsSuite)
                foreach (TestResult childResult in result.Results)
                {
                    TestResult tempResult = FindTestResult(name, childResult);
                    if (tempResult != null) return tempResult;
                }

            return null;
        }
コード例 #2
0
 public void Load(string fileSpec)
 {
     if (Directory.Exists(fileSpec))
         topLevelResult = LoadFiles(Path.Combine(fileSpec, "*.xml"));
     else if (fileSpec.IndexOfAny(new char[] { '*', '?' }) >= 0)
         topLevelResult = LoadFiles(fileSpec);
     else
         topLevelResult = LoadFile(fileSpec);
 }
コード例 #3
0
        private TestResult LoadFiles(string pattern)
        {
            TestResult topLevelResult = new TestResult(pattern, true);

            string dir = Path.GetDirectoryName(pattern);
            string pat = Path.GetFileName(pattern);

            foreach (string fileName in Directory.GetFiles(dir, pat))
            {
                topLevelResult.Results.Add(LoadFile(fileName));
            }

            return topLevelResult;
        }
コード例 #4
0
        private static TestResult FindProjectResult(string name, TestResult testResult)
        {
            if (testResult == null) return null;

            if (!testResult.IsSuite) return null;

            string resultName = testResult.Name.ToLower();
            string extension = Path.GetExtension(resultName);

            switch (extension)
            {
                case ".dll":
                case ".exe":
                    if (name.ToLower() == Path.GetFileNameWithoutExtension(resultName))
                        return testResult;
                    break;
                case "":
                    break;
                default:
                    foreach (TestResult childResult in testResult.Results)
                    {
                        if (childResult.IsSuite)
                        {
                            TestResult result = FindProjectResult(name, childResult);
                            if (result != null)
                                return result;
                        }
                    }
                    break;
            }

            return null;
        }
コード例 #5
0
        private TestResult LoadFile(string fileName)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);

            XmlNode topLevelNode = doc.SelectSingleNode("/test-results");
            //TestResult fileResult = new TestResult(fileName, true);

            XmlNode suiteNode = topLevelNode.SelectSingleNode("test-suite");
            TestResult suiteResult = new TestResult(suiteNode);

            //fileResult.Results.Add(suiteResult);

            return suiteResult;
        }
コード例 #6
0
 public TestResultAnalyzer( string name, TestResult result )
     : base(name)
 {
     this.TestResult = result;
 }
コード例 #7
0
        private static void AccumulateProjects(ArrayList list, TestResult testResult)
        {
            if (!testResult.IsSuite) return;

            string resultName = testResult.Name.ToLower();
            string extension = Path.GetExtension(resultName);

            switch (extension)
            {
                case ".dll":
                case ".exe":
                    list.Add(testResult);
                    break;
                case "":
                    break;
                default:
                    foreach (TestResult childResult in testResult.Results)
                    {
                        if (childResult.IsSuite)
                            AccumulateProjects(list, childResult);
                    }
                    break;
            }
        }
コード例 #8
0
 public TestResultAnalyzer( TestResult result )
     : this(result.Name, result)
 {
 }
コード例 #9
0
        private void SummarizeTestResults( TestResult result )
        {
            if ( result.IsTestCase )
            {
                TestCaseResults.Add( result );

                ++this.TestCount;

                switch (result.ResultState.Status)
                {
                    case TestStatus.Skipped:
                        ++this.NotRunCount;
                        break;
                    case TestStatus.Failed:
                        ++this.FailureCount;
                        break;
                    case TestStatus.Inconclusive:
                        ++this.InconclusiveCount;
                        break;
                }
            }
            else
            {
                if ( result.IsSuite )
                    foreach( TestResult childResult in result.Results )
                        SummarizeTestResults( childResult );
            }
        }
コード例 #10
0
        private bool IsParameterizedTestMethod(TestResult result)
        {
            foreach (TestResult child in result.Results)
                if ( child.IsTestCase && child.Name.EndsWith(")") )
                    return true;

            return false;
        }
コード例 #11
0
        public void FindFixtures( TestResult result )
        {
            bool hasTestCases = false;
            bool hasTestSuites = false;

            foreach( TestResult childResult in result.Results )
            {
                if ( childResult.IsTestCase || IsParameterizedTestMethod(childResult) )
                    hasTestCases = true;
                else
                    hasTestSuites = true;
            }

            if ( hasTestCases )
                Children.Add( new TestResultAnalyzer( result ) );
            else if ( hasTestSuites )
                foreach( TestResult childResult in result.Results )
                    if ( childResult.IsSuite )
                        FindFixtures(childResult );
        }
コード例 #12
0
        public TestResult(XmlNode thisNode)
        {
            this.Name = GetAttribute(thisNode, "name");
            this.Results = new List<TestResult>();

            switch (thisNode.Name)
            {
                case "test-results":
                    this.IsSuite = true;

                    XmlNode suiteNode = thisNode.SelectSingleNode("test-suite");
                    TestResult suiteResult = new TestResult(suiteNode);

                    this.Results.Add(suiteResult);
                    return;

                case "test-suite":
                    this.IsSuite = true;
                    break;

                case "test-case":
                    this.IsSuite = false;
                    break;
            }

            // Common processing for test-case and test-suite
            var result = GetAttribute(thisNode, "result");
            if (result != null) // NUnit 2.5.4 and later
            {
                if (!resultStates.ContainsKey(result))
                    throw new System.InvalidOperationException("Result file contains invalid result value: " + result);
                ResultState = resultStates[result];
            }
            else // Earlier than 2.5.4
            {
                ResultState = GetBoolean(thisNode, "executed")
                    ? GetBoolean(thisNode, "success")
                        ? ResultState.Success
                        : ResultState.Failure
                    : ResultState.Skipped;
            }

            this.Time = GetDouble(thisNode, "time");

            switch (ResultState.Status)
            {
                case TestStatus.Failed:
                    XmlNode messageNode = thisNode.SelectSingleNode("failure/message");
                    this.Message = messageNode != null ? messageNode.InnerText : string.Empty;

                    XmlNode stackTraceNode = thisNode.SelectSingleNode("failure/stack-trace");
                    this.StackTrace = stackTraceNode != null ? stackTraceNode.InnerText : string.Empty;

                    break;

                case TestStatus.Skipped:
                    XmlNode reasonNode = thisNode.SelectSingleNode("reason/message");
                    if (reasonNode != null)
                        this.Message = reasonNode.InnerText;
                    break;
            }

            if (IsSuite)
            {
                XmlNode resultsNode = thisNode.SelectSingleNode("results");

                if (resultsNode != null)
                    foreach (XmlNode childNode in resultsNode.ChildNodes)
                        this.Results.Add(new TestResult(childNode));
            }
        }