Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
PassedTests = PassedTests,
TotalTests = TotalTests,
SkippedTests = SkippedTests,
PassPercentage = (PassedTests * 100) / TotalTests,
PassPercentage = TotalTests == 0 ? 0 : PassedTests * 100 / TotalTests,
TotalRunTime = GetFormattedDurationString(e.ElapsedTimeInRunningTests),
};
if (this.parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFilePrefixKey, out string logFilePrefixValue) && !string.IsNullOrWhiteSpace(logFilePrefixValue))
Expand Down Expand Up @@ -441,4 +441,4 @@ internal string GetFormattedDurationString(TimeSpan duration)
return time.Count == 0 ? "< 1ms" : string.Join(" ", time);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,20 @@ public void TestCompleteHandlerShouldWriteToXmlSerializerCorrectly()
Assert.IsTrue(htmlLogger.HtmlFilePath.Contains(".html"));
}

[TestMethod]
public void TestCompleteHandlerShouldNotDivideByZeroWhenThereAre0TestResults()
{

this.mockFileHelper.Setup(x => x.GetStream(It.IsAny<string>(), FileMode.Create, FileAccess.ReadWrite)).Callback<string, FileMode, FileAccess>((x, y, z) =>
{
}).Returns(new Mock<Stream>().Object);

this.htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));

Assert.AreEqual(0, this.htmlLogger.TestRunDetails.Summary.TotalTests);
Assert.AreEqual(0, this.htmlLogger.TestRunDetails.Summary.PassPercentage);
}

private static TestCase CreateTestCase(string testCaseName)
{
return new TestCase(testCaseName, new Uri("some://uri"), "DummySourceFileName");
Expand Down