Created
July 28, 2013 15:53
-
-
Save Scooletz/6099052 to your computer and use it in GitHub Desktop.
A simple way of wrapping a test in a time measuring scope.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] | |
public class MeasureTimeAttribute : Attribute, ITestAction | |
{ | |
private const string Key = "stopWatch"; | |
public void BeforeTest(TestDetails testDetails) | |
{ | |
TestContext.CurrentContext.Test.Properties[Key] = Stopwatch.StartNew(); | |
} | |
public void AfterTest(TestDetails testDetails) | |
{ | |
var sw = (Stopwatch) TestContext.CurrentContext.Test.Properties[Key]; | |
sw.Stop(); | |
Console.WriteLine("Test took: " + sw.Elapsed.ToString("g")); | |
} | |
public ActionTargets Targets { get{return ActionTargets.Test;}} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment