Skip to content

Commit

Permalink
adjusted duration output to milliseconds (#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
bollhals authored Mar 14, 2022
1 parent 6831478 commit cbe64c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 19 additions & 3 deletions TechTalk.SpecFlow/Tracing/TestTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface ITestTracer

public class TestTracer : ITestTracer
{
private static readonly TimeSpan MillisecondsThreshold = TimeSpan.FromMilliseconds(300);

private readonly ITraceListener traceListener;
private readonly IStepFormatter stepFormatter;
private readonly IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider;
Expand Down Expand Up @@ -130,13 +132,27 @@ public void TraceNoMatchingStepDefinition(StepInstance stepInstance, Programming

public void TraceDuration(TimeSpan elapsed, IBindingMethod method, object[] arguments)
{
traceListener.WriteToolOutput("duration: {0}: {1:F1}s",
stepFormatter.GetMatchText(method, arguments), elapsed.TotalSeconds);
string matchText = stepFormatter.GetMatchText(method, arguments);
if (elapsed > MillisecondsThreshold)
{
traceListener.WriteToolOutput($"duration: {matchText}: {elapsed.TotalSeconds:F1}s");
}
else
{
traceListener.WriteToolOutput($"duration: {matchText}: {elapsed.TotalMilliseconds:F1}ms");
}
}

public void TraceDuration(TimeSpan elapsed, string text)
{
traceListener.WriteToolOutput("duration: {0}: {1:F1}s", text, elapsed.TotalSeconds);
if (elapsed > MillisecondsThreshold)
{
traceListener.WriteToolOutput($"duration: {text}: {elapsed.TotalSeconds:F1}s");
}
else
{
traceListener.WriteToolOutput($"duration: {text}: {elapsed.TotalMilliseconds:F1}ms");
}
}
}
}
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
3.9.58

Changes:
+ adjust the duration output to milliseconds if it's below 300ms threshold

3.9.52

Changes:
Expand Down

0 comments on commit cbe64c1

Please sign in to comment.