Since attributes don’t inherit in C# (at least I didn’t think they did) – how does the following code still display the Hello popup when the MyTestMethod test is run:
[TestClass]
public class BaseTestClass {
[TestInitialize]
public void Foo() {
System.Windows.Forms.MessageBox.Show("Hello");
}
}
[TestClass]
public class TestClass : BaseTestClass {
[TestMethod]
public void MyTestMethod() {
Assert.IsTrue(true);
}
}
Attributes are inherited by default but this can be disabled – see AttributeUsage.Inherited
If you decorate the attribute definition with an
AttributeUsageattribute, you can set this property: