public void TrxReader_SingleTrxFileInSubfolder() { // Arrange var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var resultsDir = TestUtils.CreateTestSpecificFolder(TestContext, "Dummy", "TestResults"); var trxFile = TestUtils.CreateTextFile(resultsDir, "no_attachments.trx", @"<?xml version=""1.0"" encoding=""UTF-8""?> <TestRun id=""eb906034-f363-4bf0-ac6a-29fa47645f67"" name=""LOCAL SERVICE@MACHINENAME 2015-05-06 08:38:39"" runUser=""NT AUTHORITY\LOCAL SERVICE"" xmlns=""http://microsoft.com/schemas/VisualStudio/TeamTest/2010""> <TestSettings name=""default"" id=""bf0f0911-87a2-4413-aa12-36e177a9c5b3"" /> <ResultSummary outcome=""Completed""> <Counters total=""123"" executed=""123"" passed=""123"" failed=""0"" error=""0"" timeout=""0"" aborted=""0"" inconclusive=""0"" passedButRunAborted=""0"" notRunnable=""0"" notExecuted=""0"" disconnected=""0"" warning=""0"" completed=""0"" inProgress=""0"" pending=""0"" /> <RunInfos /> <CollectorDataEntries /> </ResultSummary> </TestRun> "); var logger = new TestLogger(); // Act var coverageFilePath = new TrxFileReader(logger).LocateCodeCoverageFile(testDir); // Assert coverageFilePath.Should().BeNull(); // Not finding attachment info in the file shouldn't cause a warning/error logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); logger.AssertInfoMessageExists(trxFile); // should be a message referring to the trx }
public void TrxReader_TestsResultsDirectoryMissing() { // Arrange var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var logger = new TestLogger(); // Act var coverageFilePath = new TrxFileReader(logger).LocateCodeCoverageFile(testDir); // Assert coverageFilePath.Should().BeNull(); // Not expecting errors or warnings: we assume it means that tests have not been executed logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
public void TrxReader_TrxWithMultipleAttachments() { // Arrange var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var resultsDir = TestUtils.CreateTestSpecificFolder(TestContext, "TestResults"); TestUtils.CreateTextFile(resultsDir, "multiple_attachments.trx", @"<?xml version=""1.0"" encoding=""UTF-8""?> <TestRun id=""eb906034-f363-4bf0-ac6a-29fa47645f67"" name=""LOCAL SERVICE@MACHINENAME 2015-05-06 08:38:39"" runUser=""NT AUTHORITY\LOCAL SERVICE"" xmlns=""http://microsoft.com/schemas/VisualStudio/TeamTest/2010""> <ResultSummary outcome=""Completed""> <Counters total=""123"" executed=""123"" passed=""123"" failed=""0"" error=""0"" timeout=""0"" aborted=""0"" inconclusive=""0"" passedButRunAborted=""0"" notRunnable=""0"" notExecuted=""0"" disconnected=""0"" warning=""0"" completed=""0"" inProgress=""0"" pending=""0"" /> <RunInfos /> <CollectorDataEntries> <Collector agentName=""MACHINENAME"" uri=""datacollector://microsoft/CodeCoverage/2.0"" collectorDisplayName=""Code Coverage""> <UriAttachments> <UriAttachment> <A href=""MACHINENAME\AAA.coverage""> </A> </UriAttachment> </UriAttachments> </Collector> <Collector agentName=""MACHINENAME"" uri=""datacollector://microsoft/CodeCoverage/2.0"" collectorDisplayName=""Code Coverage""> <UriAttachments> <UriAttachment> <A href=""XXX.coverage""> </A> </UriAttachment> </UriAttachments> </Collector> </CollectorDataEntries> </ResultSummary> </TestRun> "); var logger = new TestLogger(); // Act var coverageFilePath = new TrxFileReader(logger).LocateCodeCoverageFile(testDir); // Assert coverageFilePath.Should().BeNull(); logger.AssertSingleWarningExists(@"MACHINENAME\AAA.coverage", @"XXX.coverage"); // the warning should refer to both of the coverage files logger.AssertErrorsLogged(0); }
public void TrxReader_MultipleTrxFiles() { // Arrange var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var resultsDir = TestUtils.CreateTestSpecificFolder(TestContext, "TestResults"); var trx1 = TestUtils.CreateTextFile(resultsDir, "mytrx1.trx", "<TestRun />"); var trx2 = TestUtils.CreateTextFile(resultsDir, "mytrx2.trx", "<TestRun />"); var logger = new TestLogger(); // Act var coverageFilePath = new TrxFileReader(logger).LocateCodeCoverageFile(testDir); // Assert coverageFilePath.Should().BeNull(); logger.AssertSingleWarningExists(trx1, trx2); // expecting a warning referring the log files logger.AssertErrorsLogged(0); }
public void TrxReader_InvalidTrxFile() { // Arrange var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var resultsDir = TestUtils.CreateTestSpecificFolder(TestContext, "TestResults"); TestUtils.CreateTextFile(resultsDir, "dummy.trx", "this is not a trx file"); var logger = new TestLogger(); // Act var coverageFilePath = new TrxFileReader(logger).LocateCodeCoverageFile(testDir); // Assert coverageFilePath.Should().BeNull(); logger.AssertSingleWarningExists("dummy.trx"); // expecting a warning about the invalid file logger.AssertErrorsLogged(0); // should be a warning, not an error }
public void TrxReader_SingleAttachment_Path2() { // Arrange var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var resultsDir = TestUtils.CreateTestSpecificFolder(TestContext, "TestResults"); var coverageFileName = "MACHINENAME\\LOCAL SERVICE_MACHINENAME 2015-05-06 08_38_35.coverage"; TestUtils.CreateTextFile(resultsDir, "single_attachment.trx", @"<?xml version=""1.0"" encoding=""UTF-8""?> <TestRun id=""eb906034-f363-4bf0-ac6a-29fa47645f67"" name=""LOCAL SERVICE@MACHINENAME 2015-05-06 08:38:39"" runUser=""NT AUTHORITY\LOCAL SERVICE"" xmlns=""http://microsoft.com/schemas/VisualStudio/TeamTest/2010""> <ResultSummary outcome=""Completed""> <Counters total=""123"" executed=""123"" passed=""123"" failed=""0"" error=""0"" timeout=""0"" aborted=""0"" inconclusive=""0"" passedButRunAborted=""0"" notRunnable=""0"" notExecuted=""0"" disconnected=""0"" warning=""0"" completed=""0"" inProgress=""0"" pending=""0"" /> <RunInfos /> <CollectorDataEntries> <Collector agentName=""MACHINENAME"" uri=""datacollector://microsoft/CodeCoverage/2.0"" collectorDisplayName=""Code Coverage""> <UriAttachments> <UriAttachment> <A href=""{0}""> </A> </UriAttachment> </UriAttachments> </Collector> </CollectorDataEntries> </ResultSummary> </TestRun>", coverageFileName); var logger = new TestLogger(); var expectedFilePath = Path.Combine(resultsDir, "single_attachment", "In", coverageFileName); Directory.CreateDirectory(Path.GetDirectoryName(expectedFilePath)); File.Create(expectedFilePath); // Act var coverageFilePath = new TrxFileReader(logger).LocateCodeCoverageFile(testDir); // Assert coverageFilePath.Should().Be(expectedFilePath); logger.AssertDebugMessageExists(coverageFileName); }