From bc4ccd7325235d9739868837edf01df7ca289fd1 Mon Sep 17 00:00:00 2001 From: Carlos Parra Date: Fri, 24 Aug 2018 19:49:21 -0700 Subject: [PATCH 1/3] Fixed issue #437 - Removed discover warnings --- .../MSTest.CoreAdapter/Discovery/TypeValidator.cs | 11 ++++++++--- .../Discovery/TypeValidatorTests.cs | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs b/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs index 9c46939f00..01dbf5d960 100644 --- a/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs +++ b/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs @@ -43,10 +43,15 @@ internal virtual bool IsValidTestClass(Type type, ICollection warnings) (this.reflectHelper.IsAttributeDefined(type, typeof(TestClassAttribute), false) || this.reflectHelper.HasAttributeDerivedFrom(type, typeof(TestClassAttribute), false))) { - var isPublic = type.GetTypeInfo().IsPublic || (type.GetTypeInfo().IsNested && type.GetTypeInfo().IsNestedPublic); - // non-public class - if (!isPublic) + if (type.GetTypeInfo().IsNotPublic || + (type.GetTypeInfo().IsNested && type.GetTypeInfo().IsNestedPrivate)) + { + return false; + } + + // nested non-public class + if (type.GetTypeInfo().IsNested && !type.GetTypeInfo().IsNestedPublic) { var warning = string.Format(CultureInfo.CurrentCulture, Resource.UTA_ErrorNonPublicTestClass, type.FullName); warnings.Add(warning); diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs index a27ffe653b..5b522e4f5b 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs @@ -80,12 +80,12 @@ public void IsValidTestClassShouldReturnFalseForNonPublicTestClasses() } [TestMethod] - public void IsValidTestClassShouldReportWarningForNonPublicTestClasses() + public void IsValidTestClassShouldNotReportWarningForNonPublicTestClasses() { this.SetupTestClass(); this.typeValidator.IsValidTestClass(typeof(InternalTestClass), this.warnings); - Assert.AreEqual(1, this.warnings.Count); - CollectionAssert.Contains(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(InternalTestClass).FullName)); + Assert.AreEqual(0, this.warnings.Count); + CollectionAssert.DoesNotContain(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(InternalTestClass).FullName)); } [TestMethod] From 16d5d4047d2a354754be1a8fe549d560f25377e3 Mon Sep 17 00:00:00 2001 From: Carlos Parra Date: Mon, 17 Sep 2018 11:51:51 -0700 Subject: [PATCH 2/3] Revert "Fixed issue #437 - Removed discover warnings" This reverts commit bc4ccd7325235d9739868837edf01df7ca289fd1. --- .../MSTest.CoreAdapter/Discovery/TypeValidator.cs | 11 +++-------- .../Discovery/TypeValidatorTests.cs | 6 +++--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs b/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs index 01dbf5d960..9c46939f00 100644 --- a/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs +++ b/src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs @@ -43,15 +43,10 @@ internal virtual bool IsValidTestClass(Type type, ICollection warnings) (this.reflectHelper.IsAttributeDefined(type, typeof(TestClassAttribute), false) || this.reflectHelper.HasAttributeDerivedFrom(type, typeof(TestClassAttribute), false))) { - // non-public class - if (type.GetTypeInfo().IsNotPublic || - (type.GetTypeInfo().IsNested && type.GetTypeInfo().IsNestedPrivate)) - { - return false; - } + var isPublic = type.GetTypeInfo().IsPublic || (type.GetTypeInfo().IsNested && type.GetTypeInfo().IsNestedPublic); - // nested non-public class - if (type.GetTypeInfo().IsNested && !type.GetTypeInfo().IsNestedPublic) + // non-public class + if (!isPublic) { var warning = string.Format(CultureInfo.CurrentCulture, Resource.UTA_ErrorNonPublicTestClass, type.FullName); warnings.Add(warning); diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs index 5b522e4f5b..a27ffe653b 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs @@ -80,12 +80,12 @@ public void IsValidTestClassShouldReturnFalseForNonPublicTestClasses() } [TestMethod] - public void IsValidTestClassShouldNotReportWarningForNonPublicTestClasses() + public void IsValidTestClassShouldReportWarningForNonPublicTestClasses() { this.SetupTestClass(); this.typeValidator.IsValidTestClass(typeof(InternalTestClass), this.warnings); - Assert.AreEqual(0, this.warnings.Count); - CollectionAssert.DoesNotContain(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(InternalTestClass).FullName)); + Assert.AreEqual(1, this.warnings.Count); + CollectionAssert.Contains(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(InternalTestClass).FullName)); } [TestMethod] From a189a864a6816bc9f552865d7ad794b16d61f4c0 Mon Sep 17 00:00:00 2001 From: Carlos Parra Date: Tue, 25 Sep 2018 23:45:09 -0700 Subject: [PATCH 3/3] Solved issue #437 - Removed discover warnings --- .../Execution/TestExecutionManagerTests.cs | 16 ++++++++----- .../Execution/TestMethodFilterTests.cs | 6 ++++- .../Execution/TypeCacheTests.cs | 24 +++++++++++-------- .../Execution/UnitTestRunnerTests.cs | 8 +++++-- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs index b4964a2aa9..24f2317f4f 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs @@ -865,7 +865,7 @@ private void SetTestCaseProperties(TestCase testCase, object[] propertiesValue) #region Dummy implementation - [UTF.TestClass] + [DummyTestClass] internal class DummyTestClass { public static IDictionary TestContextProperties @@ -898,7 +898,7 @@ public void IgnoredTest() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithCleanupMethods { [UTF.ClassCleanup] @@ -913,7 +913,7 @@ public void TestMethod() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassForParallelize { private static HashSet threadIds = new HashSet(); @@ -948,7 +948,7 @@ public void TestMethod2() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassForParallelize2 { private static HashSet threadIds = new HashSet(); @@ -979,7 +979,7 @@ public void TestMethod2() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassForParallelize3 { private static HashSet threadIds = new HashSet(); @@ -1004,7 +1004,7 @@ public void TestMethod1() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithDoNotParallelizeMethods { private static HashSet parallelizableTestsThreadIds = new HashSet(); @@ -1093,6 +1093,10 @@ public void TestMethod4() } } + private class DummyTestClassAttribute : UTF.TestClassAttribute + { + } + #endregion } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs index a53d5ddc45..31dac97d28 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs @@ -194,7 +194,7 @@ public void GetFilterExpressionForDiscoveryContextWithGetTestCaseFilterThrowingE Assert.AreEqual(TestMessageLevel.Error, recorder.TestMessageLevel); } - [UTF.TestClass] + [DummyTestClass] internal class DummyTestClassWithTestMethods { public UTFExtension.TestContext TestContext { get; set; } @@ -282,5 +282,9 @@ public bool MatchTestCase(TestCase testCase, Func propertyValueP throw new NotImplementedException(); } } + + private class DummyTestClassAttribute : UTF.TestClassAttribute + { + } } } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs index 3943a84714..db1c33b763 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs @@ -1236,7 +1236,7 @@ private void SetupMocks() #region dummy implementations - [UTF.TestClass] + [DummyTestClass] internal class DummyTestClassWithTestMethods { public UTFExtension.TestContext TestContext { get; set; } @@ -1308,7 +1308,7 @@ public void TestMethodWithMultipleExpectedException() } } - [UTF.TestClass] + [DummyTestClass] internal class DerivedTestClass : BaseTestClass { } @@ -1343,7 +1343,7 @@ private class DummyTestClassWithMultipleTestContextProperties : DummyTestClassWi { } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithInitializeMethods { public static void AssemblyInit(UTFExtension.TestContext tc) @@ -1355,7 +1355,7 @@ public void TestInit() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithCleanupMethods { public static void AssemblyCleanup() @@ -1367,7 +1367,7 @@ public void TestCleanup() } } - [UTF.TestClass] + [DummyTestClass] private class DummyDerivedTestClassWithInitializeMethods : DummyTestClassWithInitializeMethods { public void TestMehtod() @@ -1375,7 +1375,7 @@ public void TestMehtod() } } - [UTF.TestClass] + [DummyTestClass] private class DummyDerivedTestClassWithCleanupMethods : DummyTestClassWithCleanupMethods { public void TestMehtod() @@ -1383,7 +1383,7 @@ public void TestMehtod() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithInitAndCleanupMethods { public static void AssemblyInit(UTFExtension.TestContext tc) @@ -1399,7 +1399,7 @@ public void TestInitOrCleanup() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithIncorrectInitializeMethods { public static void TestInit(int i) @@ -1411,7 +1411,7 @@ public void AssemblyInit(UTFExtension.TestContext tc) } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithIncorrectCleanupMethods { public static void TestCleanup(int i) @@ -1423,7 +1423,7 @@ public void AssemblyCleanup() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithIncorrectTestMethodSignatures { public static void TestMethod() @@ -1435,6 +1435,10 @@ private class DerivedTestMethodAttribute : UTF.TestMethodAttribute { } + private class DummyTestClassAttribute : UTF.TestClassAttribute + { + } + #endregion } } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs index 0c47758f87..2119f6438a 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs @@ -346,7 +346,7 @@ private MSTestSettings GetSettingsWithDebugTrace(bool captureDebugTraceValue) #region Dummmy implementations - [UTF.TestClass] + [DummyTestClass] private class DummyTestClass { public UTFExtension.TestContext TestContext { get; set; } @@ -358,7 +358,7 @@ public void TestMethodToTestInProgress() } } - [UTF.TestClass] + [DummyTestClass] private class DummyTestClassWithInitializeMethods { public static Action AssemblyInitializeMethodBody { get; set; } @@ -412,6 +412,10 @@ public void TestMethod() } } + private class DummyTestClassAttribute : UTF.TestClassAttribute + { + } + #endregion } }