Beispiel #1
0
        public void GetTestsShouldNotReturnBaseTestMethodsFromAnotherAssemblyByConfiguration()
        {
            string runSettingxml =
                @"<RunSettings>   
                <MSTestV2>
                  <CaptureTraceOutput>true</CaptureTraceOutput>
                  <MapInconclusiveToFailed>false</MapInconclusiveToFailed>
                  <EnableBaseClassTestMethodsFromOtherAssemblies>false</EnableBaseClassTestMethodsFromOtherAssemblies>
              </MSTestV2>
            </RunSettings>";

            var mockRunContext  = new Mock <IRunContext>();
            var mockRunSettings = new Mock <IRunSettings>();

            mockRunContext.Setup(dc => dc.RunSettings).Returns(mockRunSettings.Object);
            mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);

            MSTestSettings.PopulateSettings(mockRunContext.Object);
            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 when RunSettings MSTestV2 specifies EnableBaseClassTestMethodsFromOtherAssemblies = false.");
        }
Beispiel #2
0
        public void GetTestsShouldNotReturnHiddenTestMethodsFromAnyLevel()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummySecondHidingTestClass), Assembly.GetExecutingAssembly().FullName);

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

            Assert.IsNotNull(tests);
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "BaseTestMethod"),
                "DummySecondHidingTestClass hides BaseTestMethod so it should be discovered.");
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "DerivedTestMethod"),
                "DummySecondHidingTestClass hides DerivedTestMethod so it should be discovered.");
            Assert.IsFalse(
                tests.Any(t => t.TestMethod.DeclaringClassFullName == typeof(DummyBaseTestClass).FullName),
                "DummySecondHidingTestClass hides all base test methods so declaring class should not be any base class");
            Assert.IsFalse(
                tests.Any(t => t.TestMethod.DeclaringClassFullName == typeof(DummyHidingTestClass).FullName),
                "DummySecondHidingTestClass hides all base test methods so declaring class should not be any base class");
            Assert.IsFalse(
                tests.Any(t => t.TestMethod.DeclaringClassFullName == typeof(DummyOverridingTestClass).FullName),
                "DummySecondHidingTestClass hides all base test methods so declaring class should not be any base class");
        }
Beispiel #3
0
        public void EnumerateShouldReturnEmptyCollectionWhenNoValidTestMethodsExist()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: false, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), string.Empty);

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

            Assert.IsNotNull(tests);
            Assert.AreEqual(0, tests.Count);
        }
Beispiel #4
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.");
        }
Beispiel #5
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.");
        }
        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);
        }
Beispiel #7
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.");
        }
        public void GetTestsShouldNotReturnBaseTestMethodsFromAnotherAssembly()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyDerivedTestClass), Assembly.GetExecutingAssembly().FullName);

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

            // This would return basic object methods like ToString() as well.
            var methodCount =
                typeof(DummyDerivedTestClass).GetMethods(BindingFlags.Instance | BindingFlags.Public).Count();

            Assert.IsNotNull(tests);
            Assert.IsTrue(methodCount > tests.Count);
        }
Beispiel #9
0
        public void GetTestsShouldReturnOverriddenTestMethods()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyOverridingTestClass), Assembly.GetExecutingAssembly().FullName);

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

            Assert.IsNotNull(tests);
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "BaseTestMethod"),
                "DummyOverridingTestClass inherits BaseTestMethod so it should be discovered.");
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "DerivedTestMethod"),
                "DummyOverridingTestClass overrides DerivedTestMethod directly so it should always be discovered.");
            Assert.AreEqual(
                typeof(DummyHidingTestClass).FullName,
                tests.Single(t => t.TestMethod.Name == "BaseTestMethod").TestMethod.DeclaringClassFullName,
                "DummyOverridingTestClass inherits BaseTestMethod from DummyHidingTestClass specifically.");
            Assert.IsNull(
                tests.Single(t => t.TestMethod.Name == "DerivedTestMethod").TestMethod.DeclaringClassFullName,
                "DummyOverridingTestClass overrides DerivedTestMethod so is the declaring class.");
        }
Beispiel #10
0
        public void EnumerateShouldReturnNullIfTypeIsNotValid()
        {
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(IDummyInterface), string.Empty);

            Assert.IsNull(typeEnumerator.Enumerate(out this.warnings));
        }