Skip to content
Open
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 @@ -102,6 +102,34 @@ public class StandardOutputTestResultParserTests : TestsBase
@"[ PASSED ] 2 test.",
};

/// <summary>
/// <see cref="https://github.com/csoltenborn/GoogleTestAdapter/issues/260"/>
/// </summary>
private string[] ConsoleOutputWithSkippedTest { get; } = @"[==========] Running 3 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 3 tests from Test
[ RUN ] Test.Succeed
[ OK ] Test.Succeed (0 ms)
[ RUN ] Test.Skip
[ SKIPPED ] Test.Skip (1 ms)
[ RUN ] Test.Fail
C:\...\test.cpp(14): error: Value of: false
Actual: false
Expected: true
[ FAILED ] Test.Fail (0 ms)
[----------] 3 tests from Test (3 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test suite ran. (6 ms total)
[ PASSED ] 1 test.
[ SKIPPED ] 1 test, listed below:
[ SKIPPED ] Test.Skip
[ FAILED ] 1 test, listed below:
[ FAILED ] Test.Fail

1 FAILED TEST
".Split('\n');


private List<string> CrashesImmediately { get; set; }
private List<string> CrashesAfterErrorMsg { get; set; }
Expand Down Expand Up @@ -276,6 +304,34 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound()
XmlTestResultParserTests.AssertTestResultIsPassed(results[1]);
}

[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_OutputWithSkippedTest_AllResultsAreFound()
{
var cases = new List<TestCase>
{
TestDataCreator.ToTestCase("Test.Succeed", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
TestDataCreator.ToTestCase("Test.Skip", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
};

var results = new StandardOutputTestResultParser(cases, ConsoleOutputWithSkippedTest, TestEnvironment.Logger).GetTestResults();

results.Should().HaveCount(3);

var result = results[0];
result.TestCase.FullyQualifiedName.Should().Be("Test.Succeed");
XmlTestResultParserTests.AssertTestResultIsPassed(result);

result = results[1];
result.TestCase.FullyQualifiedName.Should().Be("Test.Skip");
XmlTestResultParserTests.AssertTestResultIsSkipped(result);

result = results[2];
result.TestCase.FullyQualifiedName.Should().Be("Test.Fail");
XmlTestResultParserTests.AssertTestResultIsFailure(result);
}

[TestMethod]
[TestCategory(Unit)]
public void OutputHandling_OutputManyLinesWithNewlines_IsParsedCorrectly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ public class StreamingStandardOutputTestResultParserTests : TestsBase
@"[ PASSED ] 2 test.",
};

/// <summary>
/// <see cref="https://github.com/csoltenborn/GoogleTestAdapter/issues/260"/>
/// </summary>
private string[] ConsoleOutputWithSkippedTest { get; } = @"[==========] Running 3 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 3 tests from Test
[ RUN ] Test.Succeed
[ OK ] Test.Succeed (0 ms)
[ RUN ] Test.Skip
[ SKIPPED ] Test.Skip (1 ms)
[ RUN ] Test.Fail
C:\...\test.cpp(14): error: Value of: false
Actual: false
Expected: true
[ FAILED ] Test.Fail (0 ms)
[----------] 3 tests from Test (3 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test suite ran. (6 ms total)
[ PASSED ] 1 test.
[ SKIPPED ] 1 test, listed below:
[ SKIPPED ] Test.Skip
[ FAILED ] 1 test, listed below:
[ FAILED ] Test.Fail

1 FAILED TEST
".Split('\n');


private List<string> CrashesImmediately { get; set; }
private List<string> CrashesAfterErrorMsg { get; set; }
Expand Down Expand Up @@ -313,8 +341,10 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound()
@"c:\users\chris\documents\visual studio 2015\projects\consoleapplication1\consoleapplication1tests\source.cpp")
};

var results = new StandardOutputTestResultParser(cases, ConsoleOutputWithPrefixingTest, TestEnvironment.Logger)
.GetTestResults();
var parser = new StreamingStandardOutputTestResultParser(cases, MockLogger.Object, MockFrameworkReporter.Object, String.Empty);
ConsoleOutputWithPrefixingTest.ToList().ForEach(parser.ReportLine);
parser.Flush();
var results = parser.TestResults;

results.Count.Should().Be(2);
results[0].TestCase.FullyQualifiedName.Should().Be("Test.AB");
Expand All @@ -323,6 +353,37 @@ public void GetTestResults_OutputWithPrefixingTest_BothTestsAreFound()
XmlTestResultParserTests.AssertTestResultIsPassed(results[1]);
}

[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_OutputWithSkippedTest_AllResultsAreFound()
{
var cases = new List<TestCase>
{
TestDataCreator.ToTestCase("Test.Succeed", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
TestDataCreator.ToTestCase("Test.Skip", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
};

var parser = new StreamingStandardOutputTestResultParser(cases, MockLogger.Object, MockFrameworkReporter.Object, String.Empty);
ConsoleOutputWithSkippedTest.ToList().ForEach(parser.ReportLine);
parser.Flush();
var results = parser.TestResults;

results.Should().HaveCount(3);

var result = results[0];
result.TestCase.FullyQualifiedName.Should().Be("Test.Succeed");
XmlTestResultParserTests.AssertTestResultIsPassed(result);

result = results[1];
result.TestCase.FullyQualifiedName.Should().Be("Test.Skip");
XmlTestResultParserTests.AssertTestResultIsSkipped(result);

result = results[2];
result.TestCase.FullyQualifiedName.Should().Be("Test.Fail");
XmlTestResultParserTests.AssertTestResultIsFailure(result);
}

[TestMethod]
[TestCategory(Unit)]
public void OutputHandling_OutputManyLinesWithNewlines_IsParsedCorrectly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static void AssertTestResultIsPassed(Model.TestResult testResult)
testResult.ErrorMessage.Should().BeNull();
}

private void AssertTestResultIsSkipped(Model.TestResult testResult)
public static void AssertTestResultIsSkipped(Model.TestResult testResult)
{
testResult.Outcome.Should().Be(Model.TestOutcome.Skipped);
testResult.ErrorMessage.Should().BeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class StandardOutputTestResultParser
private const string Run = "[ RUN ]";
public const string Failed = "[ FAILED ]";
public const string Passed = "[ OK ]";
public const string Skipped = "[ SKIPPED ]";
public const string FailedFixture = "SetUpTestSuite or TearDownTestSuite";

public static readonly string CrashText = Resources.CrashText;
Expand Down Expand Up @@ -80,7 +81,7 @@ private TestResult CreateTestResult(int indexOfTestcase)


string errorMsg = "";
while (!(IsFailedLine(line) || IsPassedLine(line)) && currentLineIndex <= _consoleOutput.Count)
while (!(IsFailedLine(line) || IsPassedLine(line) || IsSkippedLine(line)) && currentLineIndex <= _consoleOutput.Count)
{
errorMsg += line + "\n";
line = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
Expand All @@ -97,6 +98,10 @@ private TestResult CreateTestResult(int indexOfTestcase)
{
return CreatePassedTestResult(testCase, ParseDuration(line));
}
if (IsSkippedLine(line))
{
return CreateSkippedTestResult(testCase, ParseDuration(line));
}

CrashedTestCase = testCase;
string message = CrashText;
Expand Down Expand Up @@ -163,6 +168,17 @@ public static TestResult CreatePassedTestResult(TestCase testCase, TimeSpan dura
};
}

public static TestResult CreateSkippedTestResult(TestCase testCase, TimeSpan duration)
{
return new TestResult(testCase)
{
ComputerName = Environment.MachineName,
DisplayName = testCase.DisplayName,
Outcome = TestOutcome.Skipped,
Duration = duration
};
}

public static TestResult CreateFailedTestResult(TestCase testCase, TimeSpan duration, string errorMessage, string errorStackTrace)
{
return new TestResult(testCase)
Expand Down Expand Up @@ -215,6 +231,11 @@ public static bool IsFailedLine(string line)
return line.StartsWith(Failed, StringComparison.Ordinal);
}

public static bool IsSkippedLine(string line)
{
return line.StartsWith(Skipped);
}

public static string RemovePrefix(string line)
{
return line.Substring(Run.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ private TestResult CreateTestResult()
string errorMsg = "";
while (
!(StandardOutputTestResultParser.IsFailedLine(line)
|| StandardOutputTestResultParser.IsPassedLine(line))
|| StandardOutputTestResultParser.IsPassedLine(line)
|| StandardOutputTestResultParser.IsSkippedLine(line))
&& currentLineIndex <= _consoleOutput.Count)
{
errorMsg += line + "\n";
Expand Down Expand Up @@ -229,6 +230,12 @@ private TestResult CreateTestResult()
testCase,
StandardOutputTestResultParser.ParseDuration(line, _logger));
}
if (StandardOutputTestResultParser.IsSkippedLine(line))
{
return StandardOutputTestResultParser.CreateSkippedTestResult(
testCase,
StandardOutputTestResultParser.ParseDuration(line, _logger));
}

CrashedTestCase = testCase;
string message = StandardOutputTestResultParser.CrashText;
Expand Down