Skip to content

Instantly share code, notes, and snippets.

@margusmartsepp
Created March 19, 2016 10:19
Show Gist options
  • Save margusmartsepp/23ec29009ad1588cf31f to your computer and use it in GitHub Desktop.
Save margusmartsepp/23ec29009ad1588cf31f to your computer and use it in GitHub Desktop.
Measure NUnit test times
[assembly: MeasureTimeSpan]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class |
AttributeTargets.Interface | AttributeTargets.Assembly,
AllowMultiple = true)]
public class MeasureTimeSpanAttribute : Attribute, ITestAction
{
public ActionTargets Targets => ActionTargets.Test | ActionTargets.Suite;
private Stopwatch _stopwatch;
public void BeforeTest(ITest test)
{
_stopwatch = Stopwatch.StartNew();
}
public void AfterTest(ITest test)
{
_stopwatch.Stop();
Console.WriteLine(_stopwatch.Elapsed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment