Skip to content

Commit

Permalink
Don't consider TestClassAttribute for inheritance when calculating as…
Browse files Browse the repository at this point in the history
…sembly initialize/cleanup (#4318)
  • Loading branch information
Youssef1313 authored Dec 13, 2024
1 parent 81a9a24 commit 1415e6e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private TestAssemblyInfo GetAssemblyInfo(Type type)
try
{
// Only examine classes which are TestClass or derives from TestClass attribute
if (!_reflectionHelper.IsDerivedAttributeDefined<TestClassAttribute>(t, inherit: true))
if (!_reflectionHelper.IsDerivedAttributeDefined<TestClassAttribute>(t, inherit: false))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// The test class attribute.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class STATestClassAttribute : TestClassAttribute
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
/// <item>not generic</item>
/// </list>
/// </remarks>
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class TestClassAttribute : Attribute
{
/// <summary>
Expand Down
28 changes: 14 additions & 14 deletions test/UnitTests/MSTestAdapter.UnitTests/Execution/TypeCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void GetTestMethodInfoShouldCacheAssemblyInitializeAttribute()
var testMethod = new TestMethod("TestInit", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<AssemblyInitializeAttribute>(type.GetMethod("AssemblyInit"), false)).Returns(true);
Expand All @@ -256,7 +256,7 @@ public void GetTestMethodInfoShouldCacheAssemblyCleanupAttribute()
var testMethod = new TestMethod("TestCleanup", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<AssemblyCleanupAttribute>(type.GetMethod("AssemblyCleanup"), false)).Returns(true);
Expand All @@ -276,7 +276,7 @@ public void GetTestMethodInfoShouldCacheAssemblyInitAndCleanupAttribute()
var testMethod = new TestMethod("TestInitOrCleanup", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<AssemblyInitializeAttribute>(type.GetMethod("AssemblyInit"), false)).Returns(true);
Expand All @@ -299,7 +299,7 @@ public void GetTestMethodInfoShouldThrowIfAssemblyInitHasIncorrectSignature()
var testMethod = new TestMethod("M", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<AssemblyInitializeAttribute>(type.GetMethod("AssemblyInit"), false)).Returns(true);
Expand Down Expand Up @@ -329,7 +329,7 @@ public void GetTestMethodInfoShouldThrowIfAssemblyCleanupHasIncorrectSignature()
var testMethod = new TestMethod("M", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<AssemblyCleanupAttribute>(type.GetMethod("AssemblyCleanup"), false)).Returns(true);
Expand Down Expand Up @@ -360,7 +360,7 @@ public void GetTestMethodInfoShouldCacheAssemblyInfoInstanceAndReuseTheCache()
var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_typeCache.GetTestMethodInfo(
testMethod,
Expand All @@ -372,7 +372,7 @@ public void GetTestMethodInfoShouldCacheAssemblyInfoInstanceAndReuseTheCache()
new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null, "test"), new Dictionary<string, object>()),
false);

_mockReflectHelper.Verify(rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true), Times.Once);
_mockReflectHelper.Verify(rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false), Times.Once);
Verify(_typeCache.AssemblyInfoCache.Count == 1);
}

Expand Down Expand Up @@ -477,7 +477,7 @@ public void GetTestMethodInfoShouldCacheBaseClassCleanupAttributes()
var testMethod = new TestMethod("TestMethod", type.FullName, "A", false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);
_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<ClassCleanupAttribute>(baseType.GetMethod("AssemblyCleanup"), false)).Returns(true);
_mockReflectHelper.Setup(
Expand Down Expand Up @@ -526,7 +526,7 @@ public void GetTestMethodInfoShouldCacheBaseClassInitAndCleanupAttributes()
MethodInfo baseCleanupMethod = baseType.GetMethod("ClassCleanup");

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<ClassInitializeAttribute>(baseInitializeMethod, false)).Returns(true);
Expand Down Expand Up @@ -626,7 +626,7 @@ public void GetTestMethodInfoShouldThrowIfClassInitHasIncorrectSignature()
var testMethod = new TestMethod("M", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<ClassInitializeAttribute>(type.GetMethod("AssemblyInit"), false)).Returns(true);
Expand Down Expand Up @@ -656,7 +656,7 @@ public void GetTestMethodInfoShouldThrowIfClassCleanupHasIncorrectSignature()
var testMethod = new TestMethod("M", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<ClassCleanupAttribute>(type.GetMethod("AssemblyCleanup"), false)).Returns(true);
Expand Down Expand Up @@ -726,7 +726,7 @@ public void GetTestMethodInfoShouldThrowIfTestInitOrCleanupHasIncorrectSignature
var testMethod = new TestMethod("M", type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<TestInitializeAttribute>(type.GetMethod("TestInit"), false)).Returns(true);
Expand Down Expand Up @@ -1280,7 +1280,7 @@ public void AssemblyInfoListWithExecutableCleanupMethodsShouldReturnEmptyListWhe
var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<AssemblyCleanupAttribute>(type.GetMethod("AssemblyCleanup"), false)).Returns(false);
Expand All @@ -1302,7 +1302,7 @@ public void AssemblyInfoListWithExecutableCleanupMethodsShouldReturnAssemblyInfo
var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, true)).Returns(true);
rh => rh.IsDerivedAttributeDefined<TestClassAttribute>(type, false)).Returns(true);

_mockReflectHelper.Setup(
rh => rh.IsNonDerivedAttributeDefined<AssemblyCleanupAttribute>(type.GetMethod("AssemblyCleanup"), false)).Returns(true);
Expand Down

0 comments on commit 1415e6e

Please sign in to comment.