Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vineeth Hanumanthu committed Sep 26, 2019
1 parent 4da1046 commit 5bda2ee
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/vstest.console/Internal/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e)
// Update the test count statistics based on the result of the test.
this.testsTotal++;
summary.TotalTests++;
summary.TimeSpan += e.Result.EndTime - e.Result.StartTime;
summary.TimeSpan += e.Result.Duration;
var testDisplayName = e.Result.DisplayName;

if (string.IsNullOrWhiteSpace(e.Result.DisplayName))
Expand Down
66 changes: 62 additions & 4 deletions test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Internal
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using vstest.console.Internal;
using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;
using CommandLineResources = Resources.Resources;

[TestClass]
public class ConsoleLoggerTests
Expand Down Expand Up @@ -366,7 +366,6 @@ public void InQuietModeTestErrorMessageShowShouldShowTestRunFailed()
loggerEvents.WaitForEventCompletion();

// Verify
this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunFailed, OutputLevel.Error), Times.Once());
this.mockOutput.Verify(o => o.WriteLine(message, OutputLevel.Error), Times.Once());
}

Expand Down Expand Up @@ -572,6 +571,44 @@ public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalV
this.mockProgressIndicator.Verify(pi => pi.Start(), Times.Exactly(5));
}

[TestMethod]
public void TestResultHandlerShouldWriteToConsoleShouldShowFailedTestsForQuietVebosity()
{
var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);
loggerEvents.EnableEvents();
var parameters = new Dictionary<string, string>();
parameters.Add("verbosity", "quiet");
this.consoleLogger.Initialize(loggerEvents, parameters);

foreach (var testResult in this.GetTestResultsObject())
{
loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult));
}
loggerEvents.RaiseTestRunComplete(new TestRunCompleteEventArgs(new Mock<ITestRunStatistics>().Object, false, false, null, new Collection<AttachmentSet>(), TimeSpan.FromSeconds(1)));
loggerEvents.WaitForEventCompletion();

this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryFailed, 5, 1, 1, 1, "1h 6m", "TestSource"), OutputLevel.Information), Times.Once);
}

[TestMethod]
public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForQuietVebosity()
{
var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);
loggerEvents.EnableEvents();
var parameters = new Dictionary<string, string>();
parameters.Add("verbosity", "quiet");
this.consoleLogger.Initialize(loggerEvents, parameters);

foreach (var testResult in this.GetPassedTestResultsObject())
{
loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult));
}
loggerEvents.RaiseTestRunComplete(new TestRunCompleteEventArgs(new Mock<ITestRunStatistics>().Object, false, false, null, new Collection<AttachmentSet>(), TimeSpan.FromSeconds(1)));
loggerEvents.WaitForEventCompletion();

this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryPassed, 2, 1, 0, 1, "1m 2s", "TestSource"), OutputLevel.Information), Times.Once);
}

[TestMethod]
public void TestResultHandlerShouldNotShowNotStdOutMsgOfPassedTestIfVerbosityIsNormal()
{
Expand Down Expand Up @@ -977,7 +1014,7 @@ public void DisplayFullInformationShouldWriteStdMessageWithNewLine()
this.consoleLogger.Initialize(loggerEvents, parameters);

var testresults = this.GetTestResultObject(TestOutcome.Passed);
testresults[0].Messages.Add(new TestResultMessage (TestResultMessage.StandardOutCategory, "Hello"));
testresults[0].Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, "Hello"));

foreach (var testResult in testresults)
{
Expand Down Expand Up @@ -1096,7 +1133,28 @@ private void Setup()
return testresultList;
}


private List<ObjectModel.TestResult> GetPassedTestResultsObject()
{
var testcase = new TestCase("DymmyNamespace.DummyClass.TestName", new Uri("some://uri"), "TestSource")
{
DisplayName = "TestName"
};

var testresult = new ObjectModel.TestResult(testcase)
{
Outcome = TestOutcome.Passed,
Duration = new TimeSpan(0, 0, 1, 2, 3)
};

var testresult1 = new ObjectModel.TestResult(testcase)
{
Outcome = TestOutcome.Skipped
};

var testresultList = new List<ObjectModel.TestResult> { testresult, testresult1 };

return testresultList;
}


private List<ObjectModel.TestResult> GetTestResultObject(TestOutcome outcome)
Expand Down

0 comments on commit 5bda2ee

Please sign in to comment.