예제 #1
0
        /// <summary>
        /// Generates a Visual Studio equivalent test case structure.
        /// </summary>
        /// <param name="testCase">The Boost.Test.TestCase to convert.</param>
        /// <returns>An equivalent Visual Studio TestCase structure to the one provided.</returns>

        private VSTestCase GenerateTestCase(TestCase testCase)
        {
            VSTestCase test = new VSTestCase(
                testCase.FullyQualifiedName,
                BoostTestExecutor.ExecutorUri,
                this.Source
                );

            test.DisplayName = testCase.Name;

            if (testCase.Source != null)
            {
                // NOTE As of Boost 1.61, this warning might be triggered when BOOST_DATA_TEST_CASEs are used due to irregular DOT output
                if (!Path.IsPathRooted(testCase.Source.File) && this.OutputLog)
                {
                    Logger.Info("Relative Paths are being used. Please note that test navigation from the Test Explorer window will not be available. To enable such functionality, the Use Full Paths setting under C++ -> Advanced in the project's Property Page must be set to Yes (/FC).");
                    this.OutputLog = false;
                }

                test.CodeFilePath = testCase.Source.File;
                test.LineNumber   = testCase.Source.LineNumber;
            }

            // Register the test suite as a trait
            test.Traits.Add(new Trait(VSTestModel.TestSuiteTrait, GetParentFullyQualifiedName(testCase)));

            // Register enabled and disabled as traits
            test.Traits.Add(new Trait(VSTestModel.StatusTrait, (testCase.DefaultEnabled ? VSTestModel.TestEnabled : VSTestModel.TestDisabled)));

            TestUnit unit = testCase;

            while (unit != null)
            {
                foreach (string label in unit.Labels)
                {
                    // Register each and every label as an individual trait
                    test.Traits.Add(new Trait(label, string.Empty));
                }

                // Test cases inherit the labels of parent test units
                // Reference: http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/tests_organization/tests_grouping.html
                unit = unit.Parent;
            }

            // Record Boost version if available
            if (!string.IsNullOrEmpty(this.Version))
            {
                test.SetPropertyValue(VSTestModel.VersionProperty, this.Version);
            }

            return(test);
        }
예제 #2
0
        public void ToTestElementShouldAssignTestCategoryOfUnitTestElement()
        {
            ObjectModel.TestCase   testCase     = CreateTestCase("TestCase1");
            ObjectModel.TestResult result       = new ObjectModel.TestResult(testCase);
            TestProperty           testProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "String array property", string.Empty, string.Empty, typeof(string[]), null, TestPropertyAttributes.Hidden, typeof(TestObject));

            testCase.SetPropertyValue(testProperty, new[] { "AsmLevel", "ClassLevel", "MethodLevel" });

            var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase);

            object[] expected = new[] { "MethodLevel", "ClassLevel", "AsmLevel" };

            CollectionAssert.AreEqual(expected, unitTestElement.TestCategories.ToArray().OrderByDescending(x => x.ToString()).ToArray());
        }
예제 #3
0
        public void ToTestElementShouldAssignWorkitemOfUnitTestElement()
        {
            TestPlatformObjectModel.TestCase   testCase = CreateTestCase("TestCase1");
            TestPlatformObjectModel.TestResult result   = new TestPlatformObjectModel.TestResult(testCase);
            TestProperty testProperty = TestProperty.Register("WorkItemIds", "String array property", string.Empty, string.Empty, typeof(string[]), null, TestPropertyAttributes.Hidden, typeof(TestObject));

            testCase.SetPropertyValue(testProperty, new[] { "3", "99999", "0" });

            var unitTestElement = this.converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase);

            int[] expected = new[] { 0, 3, 99999 };

            CollectionAssert.AreEquivalent(expected, unitTestElement.WorkItems.ToArray());
        }
예제 #4
0
        public void GetCustomPropertyValueFromTestCaseShouldReadCategoyrAttributesFromTestCase()
        {
            ObjectModel.TestCase testCase1    = CreateTestCase("TestCase1");
            TestProperty         testProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "String array property", string.Empty, string.Empty, typeof(string[]), null, TestPropertyAttributes.Hidden, typeof(TestObject));

            testCase1.SetPropertyValue(testProperty, new[] { "ClassLevel", "AsmLevel" });

            List <String> listCategoriesActual = Converter.GetCustomPropertyValueFromTestCase(testCase1, "MSTestDiscoverer.TestCategory");

            List <String> listCategoriesExpected = new List <string>();

            listCategoriesExpected.Add("ClassLevel");
            listCategoriesExpected.Add("AsmLevel");

            CollectionAssert.AreEqual(listCategoriesExpected, listCategoriesActual);
        }
예제 #5
0
        public void GetCustomPropertyValueFromTestCaseShouldReadWorkItemAttributesFromTestCase()
        {
            ObjectModel.TestCase testCase1    = CreateTestCase("TestCase1");
            TestProperty         testProperty = TestProperty.Register("WorkItemIds", "String array property", string.Empty, string.Empty, typeof(string[]), null, TestPropertyAttributes.Hidden, typeof(TestObject));

            testCase1.SetPropertyValue(testProperty, new[] { "99999", "0" });

            var           converter           = new Converter(new Mock <IFileHelper>().Object, new TrxFileHelper());
            List <string> listWorkItemsActual = converter.GetCustomPropertyValueFromTestCase(testCase1, "WorkItemIds");

            List <string> listWorkItemsExpected = new List <string>();

            listWorkItemsExpected.Add("99999");
            listWorkItemsExpected.Add("0");

            CollectionAssert.AreEqual(listWorkItemsExpected, listWorkItemsActual);
        }