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 @@ -41,13 +41,13 @@ public void ConstructorShouldNotInitializeNameValuePairIfEmptyXmlElementIsPassed
}

var configManager = new CollectorNameValueConfigurationManager(xmlDocument.DocumentElement);
Assert.AreEqual(0, configManager.NameValuePairs.Count);
Assert.IsEmpty(configManager.NameValuePairs);
}

[TestMethod]
public void ConstructorShouldNotInitializeNameValuePairNullIsPassed()
{
var configManager = new CollectorNameValueConfigurationManager(null);
Assert.AreEqual(0, configManager.NameValuePairs.Count);
Assert.IsEmpty(configManager.NameValuePairs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void OnEventLogEntryWrittenShouldAddLogs()
_eventLogContainer.OnEventLogEntryWritten(_eventLog, _entryWrittenEventArgs);
var newCount = _eventLogContainer.EventLogEntries.Count;

Assert.IsTrue(newCount > 0);
Assert.IsGreaterThan(0, newCount);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,21 @@ public void InitializeShouldSubscribeToDataCollectionEvents()
public void TestSessionStartEventShouldCreateEventLogContainer()
{
var eventLogDataCollector = new EventLogDataCollector();
Assert.AreEqual(0, eventLogDataCollector.ContextMap.Count);
Assert.IsEmpty(eventLogDataCollector.ContextMap);
eventLogDataCollector.Initialize(null, _mockDataCollectionEvents.Object, _mockDataCollectionSink, _mockDataCollectionLogger.Object, _dataCollectionEnvironmentContext);
_mockDataCollectionEvents.Raise(x => x.SessionStart += null, new SessionStartEventArgs());
Assert.AreEqual(1, eventLogDataCollector.ContextMap.Count);
Assert.HasCount(1, eventLogDataCollector.ContextMap);
}

[TestMethod]
public void TestCaseStartEventShouldCreateEventLogContainer()
{
var eventLogDataCollector = new EventLogDataCollector();
Assert.AreEqual(0, eventLogDataCollector.ContextMap.Count);
Assert.IsEmpty(eventLogDataCollector.ContextMap);

eventLogDataCollector.Initialize(null, _mockDataCollectionEvents.Object, _mockDataCollectionSink, _mockDataCollectionLogger.Object, _dataCollectionEnvironmentContext);
_mockDataCollectionEvents.Raise(x => x.TestCaseStart += null, new TestCaseStartEventArgs(new DataCollectionContext(new SessionId(Guid.NewGuid()), new TestExecId(Guid.NewGuid())), new TestCase()));
Assert.AreEqual(1, eventLogDataCollector.ContextMap.Count);
Assert.HasCount(1, eventLogDataCollector.ContextMap);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public EventLogSessionContextTests()
public void CreateEventLogContainerStartIndexMapShouldCreateStartIndexMap()
{
_eventLogSessionContext = new EventLogSessionContext(_eventLogContainersMap);
Assert.IsTrue(_eventLogSessionContext.EventLogContainerStartIndexMap["LogName"] == 2);
Assert.AreEqual(2, _eventLogSessionContext.EventLogContainerStartIndexMap["LogName"]);
}

[TestMethod]
public void CreateEventLogContainerEndIndexMapShouldCreateEndIndexMap()
{
_eventLogSessionContext = new EventLogSessionContext(_eventLogContainersMap);
_eventLogSessionContext.CreateEventLogContainerEndIndexMap();
Assert.IsTrue(_eventLogSessionContext.EventLogContainerEndIndexMap["LogName"] == 1);
Assert.AreEqual(1, _eventLogSessionContext.EventLogContainerEndIndexMap["LogName"]);
}

[TestMethod]
Expand All @@ -47,8 +47,8 @@ public void CreateEventLogContainerShouldNotAddIndexEntriesIfEventLogContainerMa
_eventLogSessionContext.CreateEventLogContainerStartIndexMap();
_eventLogSessionContext.CreateEventLogContainerEndIndexMap();

Assert.IsTrue(_eventLogSessionContext.EventLogContainerStartIndexMap.Count == 0);
Assert.IsTrue(_eventLogSessionContext.EventLogContainerEndIndexMap.Count == 0);
Assert.IsEmpty(_eventLogSessionContext.EventLogContainerStartIndexMap);
Assert.IsEmpty(_eventLogSessionContext.EventLogContainerEndIndexMap);
}

[TestMethod]
Expand All @@ -62,8 +62,8 @@ public void CreateEventLogContainerShouldCreateNegativeEndIndexIfLogEntriesAreEm
_eventLogSessionContext.CreateEventLogContainerStartIndexMap();
_eventLogSessionContext.CreateEventLogContainerEndIndexMap();

Assert.IsTrue(_eventLogSessionContext.EventLogContainerStartIndexMap["DummyEventLog"] == 0);
Assert.IsTrue(_eventLogSessionContext.EventLogContainerEndIndexMap["DummyEventLog"] == -1);
Assert.AreEqual(0, _eventLogSessionContext.EventLogContainerStartIndexMap["DummyEventLog"]);
Assert.AreEqual(-1, _eventLogSessionContext.EventLogContainerEndIndexMap["DummyEventLog"]);
}
}

Expand Down
7 changes: 6 additions & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

<PropertyGroup>
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
<!-- MSTEST0001 (use [TestClass]) is suppressed because several test assemblies contain
helper/base classes and non-test classes that intentionally lack [TestClass].
Addressing individually would require changes across many files; tracked for follow-up. -->
<NoWarn>$(NoWarn);MSTEST0001</NoWarn>
Comment thread
Evangelink marked this conversation as resolved.
<EnableMSTestRunner>true</EnableMSTestRunner>
<!--
Arcade uses UseMSTestRunner instead of EnableMSTestRunner
https://github.com/dotnet/arcade/blob/c9ed073c0a2a828aed8f5c6ecb0a544b0f0fd3f8/src/Microsoft.DotNet.Arcade.Sdk/tools/MSTest/MSTest.targets#L29
https://github.com/dotnet/arcade/issues/15875
https://github.com/dotnet/arcade/issues/15875
-->
<UseMSTestRunner>true</UseMSTestRunner>
<MSTestAnalysisMode>Recommended</MSTestAnalysisMode>
Comment thread
Evangelink marked this conversation as resolved.
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void BlameDataCollectorShouldNotOutputDumpFileWhenNoCrashOccurs(RunnerInf

InvokeVsTest(arguments, env);

Assert.IsFalse(StdOut.Contains(".dmp"), "it should not collect a dump, because nothing crashed");
Assert.DoesNotContain(".dmp", StdOut, "it should not collect a dump, because nothing crashed");
}

[TestMethod]
Expand All @@ -122,7 +122,7 @@ public void BlameDataCollectorShouldOutputDumpFileWhenNoCrashOccursButCollectAlw

InvokeVsTest(arguments, env);

StringAssert.Matches(StdOut, new Regex("\\.dmp"), "it should collect dump, even if nothing crashed");
Assert.MatchesRegex(new Regex("\\.dmp"), StdOut, "it should collect dump, even if nothing crashed");
}

[TestMethod]
Expand Down Expand Up @@ -260,7 +260,7 @@ public void BlameDataCollectorAeDebuggerShouldCollectDump(RunnerInfo runnerInfo)
out string standardTestOutput,
out string standardErrorTestOutput,
out int _);
Assert.IsTrue(standardErrorTestOutput.Trim().Length == 0);
Assert.AreEqual(0, standardErrorTestOutput.Trim().Length);

// Run test under postmortem monitoring
var assemblyPaths = GetAssetFullPath("BlameUnitTestProject.dll");
Expand All @@ -274,12 +274,12 @@ public void BlameDataCollectorAeDebuggerShouldCollectDump(RunnerInfo runnerInfo)
out standardTestOutput,
out standardErrorTestOutput,
out int _);
Assert.IsTrue(standardErrorTestOutput.Trim().Length == 0);
Assert.AreEqual(0, standardErrorTestOutput.Trim().Length);

// We cannot be precise here procdump is at machine level so we can have more than one dump and not only the one for our test
// We look for "at least" one dump file, is the best we can do without locking all tests.
Assert.IsTrue(Directory.GetFiles(TempDirectory.Path, "*.dmp", SearchOption.AllDirectories)
.Where(x => Path.GetFileNameWithoutExtension(x).StartsWith("testhost")).Count() > 0);
Assert.IsNotEmpty(Directory.GetFiles(TempDirectory.Path, "*.dmp", SearchOption.AllDirectories)
.Where(x => Path.GetFileNameWithoutExtension(x).StartsWith("testhost")));
}

private static bool IsAdministrator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.TestPlatform.Acceptance.IntegrationTests;

[TestClass]
public class Build : IntegrationTestBase
public static class Build
Comment thread
Evangelink marked this conversation as resolved.
{
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private static void AssertSkippedMethod(CoverageReport coverageReport)
Assert.IsNotNull(module);

var coverage = double.Parse(module.BlockCoverage, CultureInfo.InvariantCulture);
Assert.IsTrue(coverage > ExpectedMinimalModuleCoverage);
Assert.IsGreaterThan(ExpectedMinimalModuleCoverage, coverage);

var testSignFunction = module.SkippedFunctions.FirstOrDefault(f => f.Name.Equals("TestSign()"));
Assert.IsNotNull(testSignFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void DataCollectorAttachmentProcessor(RunnerInfo runnerInfo)
while (!streamReader.EndOfStream)
{
string? line = streamReader.ReadLine();
Assert.IsTrue(line!.StartsWith("SessionEnded_Handler_"));
Assert.StartsWith("SessionEnded_Handler_", line!);
fileContent.Add(line);
}
}
Expand All @@ -152,8 +152,8 @@ public void DataCollectorAttachmentProcessor(RunnerInfo runnerInfo)
foreach (var dataCollectorLogFile in dataCollectorsLogs)
{
string dataCollectorLog = File.ReadAllText(dataCollectorLogFile);
Assert.IsTrue(dataCollectorLog.Contains("MetadataReaderExtensionsHelper: Valid extension found: extension type 'DataCollector' identifier 'my://sample/datacollector' implementation 'AttachmentProcessorDataCollector.SampleDataCollectorV1' version '1'"));
Assert.IsTrue(dataCollectorLog.Contains("MetadataReaderExtensionsHelper: Valid extension found: extension type 'DataCollector' identifier 'my://sample/datacollector' implementation 'AttachmentProcessorDataCollector.SampleDataCollectorV2' version '2'"));
Assert.Contains("MetadataReaderExtensionsHelper: Valid extension found: extension type 'DataCollector' identifier 'my://sample/datacollector' implementation 'AttachmentProcessorDataCollector.SampleDataCollectorV1' version '1'", dataCollectorLog);
Assert.Contains("MetadataReaderExtensionsHelper: Valid extension found: extension type 'DataCollector' identifier 'my://sample/datacollector' implementation 'AttachmentProcessorDataCollector.SampleDataCollectorV2' version '2'", dataCollectorLog);
Assert.IsTrue(Regex.IsMatch(dataCollectorLog, @"GetTestExtensionFromType: Discovered multiple test extensions with identifier data 'my://sample/datacollector' and type 'AttachmentProcessorDataCollector\.SampleDataCollectorV1, AttachmentProcessorDataCollector, Version=.*, Culture=neutral, PublicKeyToken=null' inside file '.*AttachmentProcessorDataCollector\.dll'; keeping the first one 'AttachmentProcessorDataCollector\.SampleDataCollectorV2, AttachmentProcessorDataCollector, Version=.*, Culture=neutral, PublicKeyToken=null'\."));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public void Create_ShouldReturnListOfAttachmentProcessors()
var dataCollectorAttachmentsProcessors = _dataCollectorAttachmentsProcessorsFactory.Create(invokedDataCollectors.ToArray(), null);

// assert
Assert.AreEqual(3, dataCollectorAttachmentsProcessors.Length);
Assert.HasCount(3, dataCollectorAttachmentsProcessors);

Assert.AreEqual(1, dataCollectorAttachmentsProcessors.Count(x => x.FriendlyName == "Sample"));
Assert.AreEqual(1, dataCollectorAttachmentsProcessors.Count(x => x.FriendlyName == "SampleData3"));
Assert.AreEqual(1, dataCollectorAttachmentsProcessors.Count(x => x.FriendlyName == "Code Coverage"));
Assert.ContainsSingle(dataCollectorAttachmentsProcessors.Where(x => x.FriendlyName == "Sample"));
Assert.ContainsSingle(dataCollectorAttachmentsProcessors.Where(x => x.FriendlyName == "SampleData3"));
Assert.ContainsSingle(dataCollectorAttachmentsProcessors.Where(x => x.FriendlyName == "Code Coverage"));

Assert.AreEqual(typeof(DataCollectorAttachmentProcessor).AssemblyQualifiedName, dataCollectorAttachmentsProcessors[0].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName);
Assert.AreEqual(typeof(DataCollectorAttachmentProcessor2).AssemblyQualifiedName, dataCollectorAttachmentsProcessors[1].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName);
Expand All @@ -72,7 +72,7 @@ public void Create_EmptyOrNullInvokedDataCollector_ShouldReturnCodeCoverageDataA
var dataCollectorAttachmentsProcessors = _dataCollectorAttachmentsProcessorsFactory.Create(empty ? [] : null, null);

//assert
Assert.AreEqual(1, dataCollectorAttachmentsProcessors.Length);
Assert.ContainsSingle(dataCollectorAttachmentsProcessors);
Assert.AreEqual(typeof(CodeCoverageDataAttachmentsHandler).AssemblyQualifiedName, dataCollectorAttachmentsProcessors[0].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName);
}

Expand All @@ -91,7 +91,7 @@ public void Create_ShouldNotFailIfWrongDataCollectorAttachmentProcessor()
var dataCollectorAttachmentsProcessors = _dataCollectorAttachmentsProcessorsFactory.Create(invokedDataCollectors.ToArray(), null);

// assert
Assert.AreEqual(1, dataCollectorAttachmentsProcessors.Length);
Assert.ContainsSingle(dataCollectorAttachmentsProcessors);
Assert.AreEqual(typeof(CodeCoverageDataAttachmentsHandler).AssemblyQualifiedName, dataCollectorAttachmentsProcessors[0].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName);
}

Expand All @@ -108,7 +108,7 @@ public void Create_ShouldAddTwoTimeCodeCoverageDataAttachmentsHandler()
var dataCollectorAttachmentsProcessors = _dataCollectorAttachmentsProcessorsFactory.Create(invokedDataCollectors.ToArray(), null);

// assert
Assert.AreEqual(2, dataCollectorAttachmentsProcessors.Length);
Assert.HasCount(2, dataCollectorAttachmentsProcessors);
Assert.AreEqual(typeof(DataCollectorAttachmentProcessor).AssemblyQualifiedName, dataCollectorAttachmentsProcessors[0].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName);
Assert.AreEqual(typeof(CodeCoverageDataAttachmentsHandler).AssemblyQualifiedName, dataCollectorAttachmentsProcessors[1].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName);
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public void Create_ShouldLoadOrderingByFilePath()
var dataCollectorAttachmentsProcessors = _dataCollectorAttachmentsProcessorsFactory.Create(invokedDataCollectors.ToArray(), null);

// assert
Assert.AreEqual(2, dataCollectorAttachmentsProcessors.Length);
Assert.HasCount(2, dataCollectorAttachmentsProcessors);
Assert.IsTrue(Regex.IsMatch(dataCollectorAttachmentsProcessors[0].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName!, @"AttachmentProcessorDataCollector\.SampleDataCollectorAttachmentProcessor, AttachmentProcessorDataCollector, Version=.*, Culture=neutral, PublicKeyToken=null"));
Assert.AreEqual(Path.Combine(version2, Path.GetFileName(dataCollectorFilePath)), dataCollectorAttachmentsProcessors[0].DataCollectorAttachmentProcessorInstance.GetType().Assembly.Location);
Assert.AreEqual(typeof(CodeCoverageDataAttachmentsHandler).AssemblyQualifiedName, dataCollectorAttachmentsProcessors[1].DataCollectorAttachmentProcessorInstance.GetType().AssemblyQualifiedName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public void RunCoverletCoverage()
// This assert check that we're sure that we've updated collector setting code base with full path,
// otherwise without "custom coverlet code" inside ProxyExecutionManager coverlet dll won't be resolved inside testhost.
var log = Directory.GetFiles(logPathDirectory, $"coverletcoverage.{logId}.log").Single();
Assert.IsTrue(File.ReadAllText(log).Contains("CoverletDataCollector in-process codeBase path"));
Assert.Contains("CoverletDataCollector in-process codeBase path", File.ReadAllText(log));

// Verify out-of-proc coverlet collector load
var dataCollectorLog = Directory.GetFiles(logPathDirectory, $"coverletcoverage.{logId}.datacollector*log").Single();
Assert.IsTrue(File.ReadAllText(dataCollectorLog).Contains("[coverlet]Initializing CoverletCoverageDataCollector"));
Assert.Contains("[coverlet]Initializing CoverletCoverageDataCollector", File.ReadAllText(dataCollectorLog));

// Verify in-proc coverlet collector load
var hostLog = Directory.GetFiles(logPathDirectory, $"coverletcoverage.{logId}.host*log").Single();
Assert.IsTrue(File.ReadAllText(hostLog).Contains("[coverlet]Initialize CoverletInProcDataCollector"));
Assert.Contains("[coverlet]Initialize CoverletInProcDataCollector", File.ReadAllText(hostLog));

// Verify default coverage file is generated
StdOutputContains("coverage.cobertura.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public void RunningTestWithAFailingDebugAssertDoesNotCrashTheHostingProcess(Runn
// this will have failed tests when our trace listener works and crash the testhost process when it does not
// because crashing processes is what a failed TPDebug.Assert does by default, unless you have a debugger attached
ValidateSummaryStatus(passed: 4, failed: 4, 0);
StringAssert.Contains(StdOut, "threw exception: Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException:");
Assert.Contains("threw exception: Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException:", StdOut);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public void DiscoverTestsShouldShowProperWarningIfNoTestsOnTestCaseFilter(Runner
arguments = string.Concat(arguments, " /logger:\"console;prefix=true\"");
InvokeVsTest(arguments);

StringAssert.Contains(StdOut, "Warning: No test matches the given testcase filter `NonExistTestCaseName` in");
StringAssert.Contains(StdOut, "SimpleTestProject2.dll");
Assert.Contains("Warning: No test matches the given testcase filter `NonExistTestCaseName` in", StdOut);
Assert.Contains("SimpleTestProject2.dll", StdOut);
ExitCodeEquals(0);
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public void DiscoverTestsShouldSucceedWhenAtLeastOneDllFindsRuntimeProvider(Runn
arguments = string.Concat(arguments, " /logger:\"console;prefix=true\"");
InvokeVsTest(arguments);

StringAssert.Contains(StdOut, $"Skipping source: {nonTestDll} (.NETStandard,Version=v2.0,");
Assert.Contains($"Skipping source: {nonTestDll} (.NETStandard,Version=v2.0,", StdOut);

ExitCodeEquals(0);
}
Expand Down
Loading