diff --git a/src/vstest.console/Processors/CollectArgumentProcessor.cs b/src/vstest.console/Processors/CollectArgumentProcessor.cs
index ac5b599a20..8e22c90768 100644
--- a/src/vstest.console/Processors/CollectArgumentProcessor.cs
+++ b/src/vstest.console/Processors/CollectArgumentProcessor.cs
@@ -187,7 +187,7 @@ internal static void EnableCoverletInProcDataCollector(string argument, DataColl
{
// Set Assembly qualified name and code base if not already set
dataCollectorSettings.AssemblyQualifiedName = dataCollectorSettings.AssemblyQualifiedName ?? CoverletConstants.CoverletDataCollectorAssemblyQualifiedName;
- dataCollectorSettings.CodeBase = dataCollectorSettings.CodeBase ?? CoverletConstants.CoverletDataCollectorCodebase;
+ dataCollectorSettings.CodeBase = (dataCollectorSettings.CodeBase ?? GetCoverletCodeBasePath(runSettingProvider, fileHelper)) ?? CoverletConstants.CoverletDataCollectorCodebase;
dataCollectorSettings.IsEnabled = true;
}
}
diff --git a/test/vstest.console.UnitTests/Processors/CollectArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/CollectArgumentProcessorTests.cs
index 8ff80ffbf5..ae7287cb06 100644
--- a/test/vstest.console.UnitTests/Processors/CollectArgumentProcessorTests.cs
+++ b/test/vstest.console.UnitTests/Processors/CollectArgumentProcessorTests.cs
@@ -508,12 +508,12 @@ public void InitializeXPlatCodeCoverageShouldAddXPlatOutProcProcDataCollectorSet
" ",
" ",
" ",
- $" ",
+ $" ",
" ",
" ",
" ",
" ",
- $" ",
+ $" ",
" ",
" ",
""), this.settingsProvider.ActiveRunSettings.SettingsXml);
@@ -522,42 +522,65 @@ public void InitializeXPlatCodeCoverageShouldAddXPlatOutProcProcDataCollectorSet
[TestMethod]
public void InitializeXPlatCodeCoverageShouldAddXPlatInProcProcDataCollectoPropertiesIfNotPresent()
{
- var runsettingsString = string.Join(Environment.NewLine,
- "",
+ var runsettingsString = $"\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n";
+ runsettingsString = string.Format(runsettingsString, string.Empty);
+ var runsettings = new RunSettings();
+ runsettings.LoadSettingsXml(runsettingsString);
+ this.settingsProvider.SetActiveRunSettings(runsettings);
+ Mock fileHelper = new Mock();
+ fileHelper.Setup(f => f.Exists(It.IsAny())).Returns(true);
+ CollectArgumentExecutor executor = new CollectArgumentExecutor(settingsProvider, fileHelper.Object);
+ executor.Initialize("XPlat Code Coverage");
+
+ Assert.AreEqual(string.Join(Environment.NewLine,
+ "",
"",
" ",
" ",
" ",
" ",
" ",
+ $" ",
" ",
" ",
" ",
" ",
- $" ",
+ $" ",
" ",
" ",
- "");
+ ""), this.settingsProvider.ActiveRunSettings.SettingsXml);
+ }
+
+ [TestMethod]
+ public void InitializeXPlatCodeCoverageShouldAddXPlatInProcProcDataCollectoPropertiesIfNotPresent_NoTestAdaptersPaths()
+ {
+ var runsettingsString = $"\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n";
runsettingsString = string.Format(runsettingsString, string.Empty);
var runsettings = new RunSettings();
runsettings.LoadSettingsXml(runsettingsString);
this.settingsProvider.SetActiveRunSettings(runsettings);
- this.executor.Initialize("XPlat Code Coverage");
+ Mock fileHelper = new Mock();
+ // Suppose file exists to be sure that we won't find adapter path on runsettings config
+ fileHelper.Setup(f => f.Exists(It.IsAny())).Returns(true);
+ CollectArgumentExecutor executor = new CollectArgumentExecutor(settingsProvider, fileHelper.Object);
+ executor.Initialize("XPlat Code Coverage");
Assert.AreEqual(string.Join(Environment.NewLine,
"",
"",
+ " ",
+ " ",
" ",
" ",
" ",
" ",
" ",
- $" ",
+ $" ",
" ",
" ",
" ",
" ",
- $" ",
+ $" ",
" ",
" ",
""), this.settingsProvider.ActiveRunSettings.SettingsXml);
@@ -565,4 +588,4 @@ public void InitializeXPlatCodeCoverageShouldAddXPlatInProcProcDataCollectoPrope
#endregion
}
-}
\ No newline at end of file
+}