@@ -25,7 +25,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollect
25
25
using Microsoft . VisualStudio . TestPlatform . ObjectModel . DataCollection ;
26
26
using Microsoft . VisualStudio . TestPlatform . ObjectModel . Logging ;
27
27
using Microsoft . VisualStudio . TestPlatform . Utilities . Helpers ;
28
-
28
+ using Microsoft . VisualStudio . TestPlatform . Utilities . Helpers . Interfaces ;
29
29
using CommunicationUtilitiesResources = Microsoft . VisualStudio . TestPlatform . CommunicationUtilities . Resources . Resources ;
30
30
using CoreUtilitiesConstants = Microsoft . VisualStudio . TestPlatform . CoreUtilities . Constants ;
31
31
@@ -48,6 +48,8 @@ internal class DataCollectionRequestHandler : IDataCollectionRequestHandler, IDi
48
48
49
49
private IDataSerializer dataSerializer ;
50
50
51
+ private IFileHelper fileHelper ;
52
+
51
53
/// <summary>
52
54
/// Use to cancel data collection test case events monitoring if test run is cancelled.
53
55
/// </summary>
@@ -65,7 +67,8 @@ protected DataCollectionRequestHandler(IMessageSink messageSink)
65
67
messageSink ,
66
68
DataCollectionManager . Create ( messageSink ) ,
67
69
new DataCollectionTestCaseEventHandler ( ) ,
68
- JsonDataSerializer . Instance )
70
+ JsonDataSerializer . Instance ,
71
+ new FileHelper ( ) )
69
72
{
70
73
this . messageSink = messageSink ;
71
74
}
@@ -88,19 +91,24 @@ protected DataCollectionRequestHandler(IMessageSink messageSink)
88
91
/// <param name="dataSerializer">
89
92
/// Serializer for serialization and deserialization of the messages.
90
93
/// </param>
94
+ /// <param name="fileHelper">
95
+ /// File Helper
96
+ /// </param>
91
97
protected DataCollectionRequestHandler (
92
98
ICommunicationManager communicationManager ,
93
99
IMessageSink messageSink ,
94
100
IDataCollectionManager dataCollectionManager ,
95
101
IDataCollectionTestCaseEventHandler dataCollectionTestCaseEventHandler ,
96
- IDataSerializer dataSerializer )
102
+ IDataSerializer dataSerializer ,
103
+ IFileHelper fileHelper )
97
104
{
98
105
this . communicationManager = communicationManager ;
99
106
this . messageSink = messageSink ;
100
107
this . dataCollectionManager = dataCollectionManager ;
101
108
this . dataSerializer = dataSerializer ;
102
109
this . dataCollectionTestCaseEventHandler = dataCollectionTestCaseEventHandler ;
103
110
this . cancellationTokenSource = new CancellationTokenSource ( ) ;
111
+ this . fileHelper = fileHelper ;
104
112
}
105
113
106
114
/// <summary>
@@ -137,7 +145,8 @@ public static DataCollectionRequestHandler Create(
137
145
messageSink ,
138
146
DataCollectionManager . Create ( messageSink ) ,
139
147
new DataCollectionTestCaseEventHandler ( ) ,
140
- JsonDataSerializer . Instance ) ;
148
+ JsonDataSerializer . Instance ,
149
+ new FileHelper ( ) ) ;
141
150
}
142
151
}
143
152
}
@@ -228,40 +237,49 @@ public void Close()
228
237
/// <summary>
229
238
/// Update the test adapter paths provided through run settings to be used by the test plugin cache.
230
239
/// </summary>
231
- /// <param name="runSettings ">
232
- /// The run Settings.
240
+ /// <param name="payload ">
241
+ /// The before test run start payload
233
242
/// </param>
234
- private void AddExtensionAssemblies ( string runSettings )
243
+ private void AddExtensionAssemblies ( BeforeTestRunStartPayload payload )
235
244
{
236
245
try
237
246
{
238
- IEnumerable < string > customTestAdaptersPaths = RunSettingsUtilities . GetTestAdaptersPaths ( runSettings ) ;
247
+ var customTestAdaptersPaths = RunSettingsUtilities . GetTestAdaptersPaths ( payload . SettingsXml ) ;
248
+
249
+ // In case of dotnet vstest with code coverage, data collector needs to be picked up from publish folder.
250
+ // Therefore, adding source dll folders to search datacollectors in these.
251
+ var datacollectorSearchPaths = new HashSet < string > ( ) ;
252
+ foreach ( var source in payload . Sources )
253
+ {
254
+ datacollectorSearchPaths . Add ( Path . GetDirectoryName ( source ) ) ;
255
+ }
256
+
239
257
if ( customTestAdaptersPaths != null )
240
258
{
241
- var fileHelper = new FileHelper ( ) ;
259
+ datacollectorSearchPaths . UnionWith ( customTestAdaptersPaths ) ;
260
+ }
242
261
243
- List < string > extensionAssemblies = new List < string > ( ) ;
244
- foreach ( var customTestAdaptersPath in customTestAdaptersPaths )
262
+ List < string > extensionAssemblies = new List < string > ( ) ;
263
+ foreach ( var datacollectorSearchPath in datacollectorSearchPaths )
264
+ {
265
+ var adapterPath =
266
+ Path . GetFullPath ( Environment . ExpandEnvironmentVariables ( datacollectorSearchPath ) ) ;
267
+ if ( ! this . fileHelper . DirectoryExists ( adapterPath ) )
245
268
{
246
- var adapterPath =
247
- Path . GetFullPath ( Environment . ExpandEnvironmentVariables ( customTestAdaptersPath ) ) ;
248
- if ( ! fileHelper . DirectoryExists ( adapterPath ) )
249
- {
250
- EqtTrace . Warning ( string . Format ( "AdapterPath Not Found:" , adapterPath ) ) ;
251
- continue ;
252
- }
253
-
254
- extensionAssemblies . AddRange (
255
- fileHelper . EnumerateFiles (
256
- adapterPath ,
257
- SearchOption . AllDirectories ,
258
- TestPlatformConstants . DataCollectorEndsWithPattern ) ) ;
269
+ EqtTrace . Warning ( string . Format ( "AdapterPath Not Found:" , adapterPath ) ) ;
270
+ continue ;
259
271
}
260
272
261
- if ( extensionAssemblies . Count > 0 )
262
- {
263
- TestPluginCache . Instance . UpdateExtensions ( extensionAssemblies , skipExtensionFilters : false ) ;
264
- }
273
+ extensionAssemblies . AddRange (
274
+ this . fileHelper . EnumerateFiles (
275
+ adapterPath ,
276
+ SearchOption . AllDirectories ,
277
+ TestPlatformConstants . DataCollectorEndsWithPattern ) ) ;
278
+ }
279
+
280
+ if ( extensionAssemblies . Count > 0 )
281
+ {
282
+ TestPluginCache . Instance . UpdateExtensions ( extensionAssemblies , skipExtensionFilters : false ) ;
265
283
}
266
284
}
267
285
catch ( Exception e )
@@ -278,7 +296,7 @@ private void HandleBeforeTestRunStart(Message message)
278
296
{
279
297
// Initialize datacollectors and get enviornment variables.
280
298
var payload = this . dataSerializer . DeserializePayload < BeforeTestRunStartPayload > ( message ) ;
281
- this . AddExtensionAssemblies ( payload . SettingsXml ) ;
299
+ this . AddExtensionAssemblies ( payload ) ;
282
300
283
301
var envVariables = this . dataCollectionManager . InitializeDataCollectors ( payload . SettingsXml ) ;
284
302
0 commit comments