I have created a custom Attribute debugging it realised that it get called so many times even I run just ONE test. Seems like it get called for attributes for all tests:
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class |
AttributeTargets.Interface | AttributeTargets.Assembly,
AllowMultiple = true)]
public class DisplayModeAttribute : Attribute, ITestAction
{
private readonly string screenSize;
public DisplayModeAttribute(string screenSize)
{
this.screenSize = screenSize;
}
public void BeforeTest(TestDetails details)
{
PageFactory.SetWindowSize(screenSize);
}
public void AfterTest(TestDetails details)
{
}
public ActionTargets Targets
{
get { return ActionTargets.Test | ActionTargets.Suite; }
}
}
I have Three tests that are using this attribute with small, large xsmall values as
[DisplayMode("small")]
When I debug a test I notice that attribute constructor get called with all the values (small, large, xsmall) each for many times (around 40!). And for the final call it sets the value with the correct value e.g "small"
Checking the call stack I can't see it get called by whom.