예제 #1
0
        public void GetTestsShouldReturnBaseTestMethodsInSameAssembly()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyDerivedTestClass), Assembly.GetExecutingAssembly().FullName);

            var tests = typeEnumerator.Enumerate(out this.warnings);

            Assert.IsNotNull(tests);
            Assert.IsTrue(
                tests.Any(t => t.TestMethod.Name == "BaseTestMethod"),
                "DummyDerivedTestClass inherits DummyBaseTestClass from same assembly. BestTestMethod from DummyBaseTestClass should be discovered.");
        }
예제 #2
0
        public void GetTestsShouldReturnDeclaredTestMethods()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyBaseTestClass), Assembly.GetExecutingAssembly().FullName);

            var tests = typeEnumerator.Enumerate(out this.warnings);

            Assert.IsNotNull(tests);
            Assert.IsTrue(
                tests.Any(t => t.TestMethod.Name == "BaseTestMethod"),
                "DummyBaseTestClass declares BaseTestMethod directly so it should always be discovered.");
        }
예제 #3
0
        public void ThrowsExceptionWithLamdaExpressionsShouldThrowAssertionOnWrongException()
        {
            var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.ThrowsException <ArgumentException>(
                                                                       () =>
            {
                throw new FormatException();
            }));

            Assert.IsNotNull(ex);
            Assert.AreEqual(typeof(TestFrameworkV2.AssertFailedException), ex.GetType());
            StringAssert.Contains(ex.Message, "Assert.ThrowsException failed. Threw exception FormatException, but exception ArgumentException was expected.");
        }
예제 #4
0
        public void GetTestsShouldReturnBaseTestMethodsInSameAssembly()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyDerivedTestClass), Assembly.GetExecutingAssembly().FullName);

            var tests = typeEnumerator.Enumerate(out this.warnings);

            var methodCount = typeof(DummyDerivedTestClass).GetMethods(BindingFlags.Instance | BindingFlags.Public).Count(m => m.DeclaringType.Assembly == typeof(DummyDerivedTestClass).Assembly);

            Assert.IsNotNull(tests);
            Assert.AreEqual(methodCount, tests.Count);
        }
예제 #5
0
        public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
        {
            var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1");

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(2, attribs.Length);

            var expectedAttribs = new string[] { "TestCategory : derived", "Owner : derived" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #6
0
        public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()
        {
            var asm = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").Assembly;

            var attribs = this.reflectionUtility.GetCustomAttributes(asm, typeof(TestCategoryV2));

            Assert.IsNotNull(attribs);
            Assert.AreEqual(2, attribs.Length);

            var expectedAttribs = new string[] { "TestCategory : a1", "TestCategory : a2" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #7
0
        public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance()
        {
            var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetTypeInfo();

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(TestCategoryV2), true);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(2, attribs.Length);

            var expectedAttribs = new string[] { "TestCategory : a", "TestCategory : ba" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #8
0
        public void GetSpecificCustomAttributesShouldReturnArrayAttributesAsWell()
        {
            var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyTestMethod2");

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(CategoryArrayAttribute), true);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(1, attribs.Length);

            var expectedAttribs = new string[] { "CategoryAttribute : foo,foo2" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #9
0
        public void GetSpecificCustomAttributesShouldReturnAllAttributesIncludingUserDefinedAttributes()
        {
            var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyVTestMethod1");

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(TestPropertyV2), true);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(1, attribs.Length);

            var expectedAttribs = new string[] { "Duration : superfast" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #10
0
        public void GetSpecificCustomAttributesShouldReturnAllAttributes()
        {
            var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestBaseClass").GetMethod("DummyVTestMethod1");

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(TestCategoryV2), false);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(1, attribs.Length);

            var expectedAttribs = new string[] { "TestCategory : base" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #11
0
        public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance()
        {
            var tinfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetTypeInfo();

            var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(1, attribs.Length);

            var expectedAttribs = new string[] { "TestCategory : a" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #12
0
        public void GetTestsShouldNotReturnBaseTestMethodsFromAnotherAssemblyByDefault()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: false);

            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyDerivedTestClass), Assembly.GetExecutingAssembly().FullName);

            var tests = typeEnumerator.Enumerate(out this.warnings);

            Assert.IsNotNull(tests);
            Assert.IsTrue(
                tests.All(t => t.TestMethod.Name != "BaseTestMethod"),
                "DummyDerivedFromRemoteTestClass inherits DummyRemoteBaseTestClass from different assembly. BestTestMethod from DummyRemoteBaseTestClass should not be discovered by default.");
        }
예제 #13
0
        public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes()
        {
            var tinfo = typeof(DummyBaseTestClass).GetTypeInfo();

            var attribs = this.reflectionOperations.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(1, attribs.Length);

            var expectedAttribs = new string[] { "DummyA : ba" };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #14
0
        public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
        {
            var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");

            var attribs = this.reflectionOperations.GetCustomAttributes(minfo, typeof(DummyAAttribute), true);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(2, attribs.Length);

            var expectedAttribs = new string[] { "DummyA : derived", "DummyA : base", };

            CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs));
        }
예제 #15
0
        public void TestSettingsFileShouldNotBeNullWhenSpecifiedInRunSettings()
        {
            string runSettingxml =
                @"<RunSettings>
                 <MSTest>   
                   <SettingsFile>DummyPath\\TestSettings1.testsettings</SettingsFile>
                 </MSTest>
               </RunSettings>";

            MSTestSettings adapterSettings = MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsName);

            Assert.IsNotNull(adapterSettings.TestSettingsFile);
        }
예제 #16
0
        public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()
        {
            var asm = typeof(DummyTestClass).GetTypeInfo().Assembly;

            var attribs = this.reflectionUtility.GetCustomAttributes(asm, typeof(DummyAAttribute));

            Assert.IsNotNull(attribs);
            Assert.AreEqual(2, attribs.Length);

            var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" };

            CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
        }
예제 #17
0
        public void GetTestFromMethodShouldInitiateTestMethodWithCorrectParameters()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");

            var testElement = typeEnumerator.GetTestFromMethod(typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType"), true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.AreEqual("MethodWithVoidReturnType", testElement.TestMethod.Name);
            Assert.AreEqual(typeof(DummyTestClass).FullName, testElement.TestMethod.FullClassName);
            Assert.AreEqual("DummyAssemblyName", testElement.TestMethod.AssemblyName);
            Assert.IsFalse(testElement.TestMethod.IsAsync);
        }
        public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
        {
            var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(2, attribs.Length);

            var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived" };

            CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
        }
예제 #19
0
        public void GetTypesShouldReturnReflectionTypeLoadExceptionTypesOnException()
        {
            Mock <TestableAssembly> mockAssembly = new Mock <TestableAssembly>();
            var reflectedTypes = new Type[] { typeof(DummyTestClass) };

            // Setup mocks
            mockAssembly.Setup(a => a.DefinedTypes).Throws(new ReflectionTypeLoadException(reflectedTypes, null));

            var types = this.assemblyEnumerator.GetTypes(mockAssembly.Object, string.Empty, this.warnings);

            Assert.IsNotNull(types);
            CollectionAssert.AreEqual(reflectedTypes, types);
        }
        public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance()
        {
            var tinfo = typeof(DummyTestClass).GetTypeInfo();

            var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(1, attribs.Length);

            var expectedAttribs = new string[] { "DummyA : a" };

            CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
        }
        public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance()
        {
            var minfo = typeof(DummyTestClass).GetTypeInfo();

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(2, attribs.Length);

            var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" };

            CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
        }
        public void GetSpecificCustomAttributesShouldReturnAllAttributes()
        {
            var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(1, attribs.Length);

            var expectedAttribs = new string[] { "DummyA : base" };

            CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
        }
        public void GetTestsShouldReturnTestElements()
        {
            var assemblyName = Assembly.GetExecutingAssembly().FullName;

            // Setup mocks.
            this.SetupMocks(assemblyName, doesFileExist: true, isAssemblyReferenced: true);

            var tests = this.testableAssemblyEnumeratorWrapper.GetTests(assemblyName, null, out this.warnings);

            Assert.IsNotNull(tests);

            // Validate if the current test is enumerated in this list.
            Assert.IsTrue(tests.Any(t => t.TestMethod.Name == "ValidTestMethod"));
        }
예제 #24
0
        public void RunClassInitializeShouldThrowForAlreadyExecutedTestClassInitWithException()
        {
            DummyTestClass.ClassInitializeMethodBody        = (tc) => { };
            this.testClassInfo.ClassInitializeMethod        = typeof(DummyTestClass).GetMethod("ClassInitializeMethod");
            this.testClassInfo.ClassInitializationException = new TestFailedException(UnitTestOutcome.Failed, "Cached Test failure");

            var exception = ActionUtility.PerformActionAndReturnException(() => this.testClassInfo.RunClassInitialize(this.testContext)) as TestFailedException;

            Assert.IsNotNull(exception);
            Assert.AreEqual(UnitTestOutcome.Failed, exception.Outcome);
            Assert.AreEqual(
                "Cached Test failure",
                exception.Message);
        }
예제 #25
0
        public void RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive()
        {
            DummyTestClass.ClassInitializeMethodBody = (tc) => UTF.Assert.Inconclusive("Test Inconclusive");
            this.testClassInfo.ClassInitializeMethod = typeof(DummyTestClass).GetMethod("ClassInitializeMethod");

            var exception = ActionUtility.PerformActionAndReturnException(() => this.testClassInfo.RunClassInitialize(this.testContext)) as TestFailedException;

            Assert.IsNotNull(exception);
            Assert.AreEqual(UnitTestOutcome.Inconclusive, exception.Outcome);
            StringAssert.Contains(exception.Message, "Test Inconclusive");
            StringAssert.StartsWith(
                exception.StackTraceInformation.ErrorStackTrace,
                "   at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>");
        }
        public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
        {
            var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");

            var attribs = this.reflectionUtility.GetCustomAttributes(minfo, true);

            Assert.IsNotNull(attribs);
            Assert.AreEqual(3, attribs.Length);

            // Notice that the DummySingleA on the base method does not show up since it can only be defined once.
            var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", };

            CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
        }
예제 #27
0
        public void GetTestFromMethodShouldSetPriority()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.GetPriority(methodInfo)).Returns(1);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.AreEqual(1, testElement.Priority);
        }
예제 #28
0
        public void GetSettingsShouldBeAbleToReadAfterParallelizationSettingsOnEmptyParallelizationNode()
        {
            string runSettingxml =
                @"<RunSettings>
                    <MSTestV2>
                        <Parallelize/>
                        <SettingsFile>DummyPath\\TestSettings1.testsettings</SettingsFile>
                    </MSTestV2>
                  </RunSettings>";

            MSTestSettings adapterSettings = MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsNameAlias);

            Assert.IsNotNull(adapterSettings.TestSettingsFile);
        }
예제 #29
0
        public void RunSingleTestShouldReturnTestResultIndicateATestNotFoundIfTestMethodCannotBeFound()
        {
            var testMethod = new TestMethod("M", "C", "A", isAsync: false);

            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny <bool>()))
            .Returns(Assembly.GetExecutingAssembly());

            var results = this.unitTestRunner.RunSingleTest(testMethod, this.testRunParameters);

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Length);
            Assert.AreEqual(UnitTestOutcome.NotFound, results[0].Outcome);
            Assert.AreEqual("Test method M was not found.", results[0].ErrorMessage);
        }
예제 #30
0
        public void GetTestFromMethodShouldSetDoNotParallelize()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(It.IsAny <MemberInfo>(), typeof(UTF.DoNotParallelizeAttribute))).Returns(new[] { new UTF.DoNotParallelizeAttribute() });

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.IsTrue(testElement.DoNotParallelize);
        }