Ejemplo n.º 1
0
        public void InsertTestCase(TestCaseResult testCase, XDocument trxDocument)
        {
            Guid testguid = TrxHelper.GuidFromString(string.Format("{0}.{1}", testCase.ModuleName, testCase.TestCaseName));
            Guid executionId = Guid.NewGuid();

            InsertTestDefinition(testCase, trxDocument, testguid, executionId);
            InsertTestEntry(trxDocument, testguid, executionId);
            InsertTestResult(testCase, trxDocument, testguid, executionId);
        }
Ejemplo n.º 2
0
        private static void InsertTestDefinition(TestCaseResult testCase, XDocument trxDocument, Guid testguid, Guid executionId)
        {
            string classNameWithAssembly = string.Format("{0}, {1}", testCase.ModuleName, testCase.TestSuiteName);

            var unitTestElement = new XElement(TrxHelper.XmlNamespace + "UnitTest",
                new XAttribute("id", testguid),
                new XAttribute("name", string.Format("{0}: {1}", testCase.ModuleName, testCase.TestCaseName)),
                new XElement(TrxHelper.XmlNamespace + "Execution",
                    new XAttribute("id", executionId)),
                new XElement(TrxHelper.XmlNamespace + "TestMethod",
                    new XAttribute("adapterTypeName", vsTestAdapterType),
                    new XAttribute("className", classNameWithAssembly),
                    new XAttribute("codeBase", testCase.TestSuiteName),
                    new XAttribute("name", testCase.TestCaseName)));

            var testDefinitionsNode = trxDocument.Root.Element(TrxHelper.XmlNamespace + "TestDefinitions");
            testDefinitionsNode.Add(unitTestElement);
        }
Ejemplo n.º 3
0
        private void InsertTestResult(TestCaseResult testCase, XDocument trxDocument, Guid testguid, Guid executionId)
        {
            var unitTestResultElement = new XElement(TrxHelper.XmlNamespace + "UnitTestResult",
                new XAttribute("executionId", executionId),
                new XAttribute("testId", testguid),
                new XAttribute("testName", testCase.TestCaseName),
                new XAttribute("computerName", ""),
                new XAttribute("testListId", defaultTestListId),
                new XAttribute("testType", unitTestType));

            unitTestResultElement.Add(new XAttribute("duration", testCase.Duration));
            //unitTestResultElement.Add(new XAttribute("startTime", runTime));
            //runTime = runTime + testCase.Duration;
            //unitTestResultElement.Add(new XAttribute("endTime", runTime));

            unitTestResultElement.Add(new XAttribute("outcome", testCase.Result));

            var outputElement = new XElement(TrxHelper.XmlNamespace + "Output");
            unitTestResultElement.Add(outputElement);

            if (string.IsNullOrEmpty(testCase.Message) == false)
            {
                var messageElement = new XElement(TrxHelper.XmlNamespace + "TextMessages",
                        new XElement(TrxHelper.XmlNamespace + "Message", testCase.Message));

                outputElement.Add(messageElement);
            }

            if (string.IsNullOrEmpty(testCase.StackTrace) == false)
            {
                var messageElement = new XElement(TrxHelper.XmlNamespace + "ErrorInfo",
                        new XElement(TrxHelper.XmlNamespace + "StackTrace", testCase.StackTrace));

                outputElement.Add(messageElement);
            }

            var resultsNode = trxDocument.Root.Element(TrxHelper.XmlNamespace + "Results");
            resultsNode.Add(unitTestResultElement);
        }
Ejemplo n.º 4
0
        private TestCaseResult ParseTest(testcaseType test)
        {
            var result = new TestCaseResult();

            string fullName = test.name;
            result.TestCaseName = test.name.Substring(fullName.LastIndexOf('.') + 1);
            result.ModuleName = test.name.Substring(0, fullName.LastIndexOf('.'));

            if (bool.Parse(test.executed) == true)
            {
                if (string.IsNullOrEmpty(test.time) == false)
                {
                    string[] time = test.time.Split('.');
                    result.Duration = new TimeSpan(0, 0, 0, int.Parse(time[0]), int.Parse(time[1]));
                }
            }

            result.Result = ConvertNUnitResultStatus(test.result);

            if (test.Item is reasonType)
            {
                var reason = test.Item as reasonType;
                result.Message = reason.message;
            }

            if (test.Item is failureType)
            {
                var failure = test.Item as failureType;
                result.Message = failure.message;
                result.StackTrace = failure.stacktrace;
            }

            return result;
        }