-
Notifications
You must be signed in to change notification settings - Fork 0
/
NUnitProjects.targets
200 lines (173 loc) · 12.3 KB
/
NUnitProjects.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PrepareNUnitRunner">
<!--
Look for the NUnit tools directory.
LastMatch is used so that we get the highest version of runner available.
-->
<ItemGroup>
<NUnitPaths Include="packages\Nunit*\tools\nunit3-console.exe" />
<NUnitPaths Include="packages\Nunit*\*\tools\nunit3-console.exe" />
</ItemGroup>
<FindInList List="@(NUnitPaths)" FindLastMatch="true" ItemSpecToFind="%(NUnitPaths.Identity)" >
<Output TaskParameter="ItemFound" PropertyName="NUnitRunnerPath"/>
</FindInList>
<Message Text="NUnit runner paths: @(NUnitPaths)" />
<Error Condition="'$(NUnitRunnerPath)' == ''" Text="Could not find NUnit runner executable." />
<Error Condition="!Exists('$(NUnitRunnerPath)')" Text="Could not find NUnit runner executable." />
<Message Text="Using NUnit at: $(NUnitRunnerPath)" />
<PropertyGroup>
<NumberOfParallelAgents>$(NUMBER_OF_PROCESSORS)</NumberOfParallelAgents>
<NumberOfParallelAgents Condition="'$(NumberOfParallelAgents)' == ''">4</NumberOfParallelAgents>
</PropertyGroup>
<Message Text="Limit NUnit agent concurrency to $(NumberOfParallelAgents)" />
</Target>
<Target Name="PrepareTeamCityVSTestAdapterPath" Condition="'$(UseTeamCityLogging)' == 'True'">
<ItemGroup>
<TeamCityVSTestAdapterPaths Include="packages\teamcity.vstest.testadapter\*\build\_common\vstest*\TeamCity.VSTest.TestAdapter.dll" />
</ItemGroup>
<ItemGroup>
<TeamCityVSTestAdapterDirectories Include="@(TeamCityVSTestAdapterPaths->'%(RelativeDir)')" />
</ItemGroup>
<FindInList List="@(TeamCityVSTestAdapterDirectories)" FindLastMatch="true" ItemSpecToFind="%(TeamCityVSTestAdapterDirectories.Identity)" Condition="'@(TeamCityVSTestAdapterDirectories)' != ''" >
<Output TaskParameter="ItemFound" PropertyName="TeamCityVSTestAdapterPath"/>
</FindInList>
<Message Text="TeamCity VSTest adapter paths: @(TeamCityVSTestAdapterPaths)" />
<Message Text="Using TeamCity VSTest adapter at: $(TeamCityVSTestAdapterPath)" />
</Target>
<Target Name="PrepareDotCover" Condition="'$(DotCoverConfigurationFile)' != ''">
<!--
Look for the dotCover command line runner.
LastMatch is used so that we get the highest version of runner available.
-->
<ItemGroup>
<DotCoverPaths Condition="'$(agent_home_dir)' != ''" Include="$(agent_home_dir)\tools\**\dotCover.exe" />
<DotCoverPaths Include="packages\JetBrains.dotCover.CommandLineTools*\tools\dotCover.exe" />
<DotCoverPaths Include="packages\JetBrains.dotCover.CommandLineTools\*\tools\dotCover.exe" />
</ItemGroup>
<ItemGroup>
<DotCoverDirectories Include="@(DotCoverPaths->'%(RootDir)%(Directory)')" />
</ItemGroup>
<FindInList List="@(DotCoverDirectories)" FindLastMatch="true" ItemSpecToFind="%(DotCoverDirectories.Identity)" Condition="'@(DotCoverDirectories)' != ''">
<Output TaskParameter="ItemFound" PropertyName="DotCoverRunnerDirectory"/>
</FindInList>
<Message Text="dotCover runner paths: @(DotCoverPaths)" />
<Message Text="dotCover runner directories: @(DotCoverDirectories)" />
<Message Condition="'$(DotCoverRunnerDirectory)' == ''" Text="Could not find dotCover runner executable." />
<PropertyGroup>
<DotCoverRunnerPath Condition="'$(DotCoverRunnerDirectory)' != ''">$(DotCoverRunnerDirectory)dotCover.exe</DotCoverRunnerPath>
</PropertyGroup>
<Error Condition="'$(DotCoverRunnerPath)' != '' And !Exists('$(DotCoverRunnerPath)')" Text="Could not find dotCover runner executable." />
<Message Text="##teamcity[dotNetCoverage dotcover_home='$(DotCoverRunnerDirectory)']" Condition="'$(DotCoverRunnerPath)' != ''" />
<Message Text="Using dotCover at: $(DotCoverRunnerPath)" Condition="'$(DotCoverRunnerPath)' != ''" />
<ItemGroup>
<NUnitFilters Include="cat != ExcludeFromCodeCoverage" />
<DotNetTestFilters Include="TestCategory!=ExcludeFromCodeCoverage" />
</ItemGroup>
</Target>
<Target Name="BuildNUnitTestAssemblies" Condition="'@(NUnitProjects)' != ''">
<MSBuild Projects="@(NUnitProjects)" Targets="DispatchToInnerBuilds" ToolsVersion="$(PreferredMSBuildToolsVersion)" BuildInParallel="true" Properties="@(_BuildProperties);InnerTargets=Build" >
<Output TaskParameter="TargetOutputs" ItemName="NUnitProjectAssemblies" />
</MSBuild>
<Error Condition="'@(NUnitProjectAssemblies)' == ''" Text="NUnit projects were found, but the build produced no assemblies." />
<ConvertToAbsolutePath Paths="@(NUnitProjects)">
<Output TaskParameter="AbsolutePaths" ItemName="NUnitProjectsAbsolute" />
</ConvertToAbsolutePath>
<ItemGroup>
<NUnitProjectsOutputs Include="%(NUnitProjectAssemblies.MSBuildSourceProjectFile)">
<TargetPath>%(NUnitProjectAssemblies.Identity)</TargetPath>
<TargetFrameworkIdentifier>%(NUnitProjectAssemblies.TargetFrameworkIdentifier)</TargetFrameworkIdentifier>
</NUnitProjectsOutputs>
<NUnitTestProjectsWithDependsOn Include="%(Identity)" Condition="'@(NUnitProjectsAbsolute->'%(DependsOn)')' != ''" >
<DependsOn>@(NUnitProjectsAbsolute->'%(DependsOn)')</DependsOn>
</NUnitTestProjectsWithDependsOn>
<NUnitTestAssemblies Include="@(NUnitProjectsOutputs->'%(TargetPath)')">
<OriginalProject>%(NUnitProjectsOutputs.Identity)</OriginalProject>
<DotCoverSnapshot>%(TargetPath).dcvr</DotCoverSnapshot>
<UseDotNetTest Condition="'%(TargetFrameworkIdentifier)' == '.NETCoreApp'">True</UseDotNetTest>
</NUnitTestAssemblies>
</ItemGroup>
</Target>
<Target Name="_SelectCoverageTool" DependsOnTargets="PrepareDotCover">
<PropertyGroup>
<CoverageToolName Condition="'$(DotCoverRunnerPath)' != ''">DotCover</CoverageToolName>
<CoverageToolName Condition="'$(CoverageToolName)' == ''">*NONE*</CoverageToolName>
</PropertyGroup>
<Message Text="Coverage tool: $(CoverageToolName)" />
</Target>
<Target Name="RunNUnitTests" Condition="'@(NUnitProjects)' != ''" DependsOnTargets="_SelectCoverageTool;RunNUnitTestsOnly;RunNUnitTestsWithDotCover">
</Target>
<Target Name="RunNUnitTestsOnly" Condition="'$(CoverageToolName)' == '*NONE*'" DependsOnTargets="_RunNUnitTestsOnly">
</Target>
<Target Name="_BuildNUnitTestsDependsOn" Inputs="@(NUnitTestProjectsWithDependsOn)" Outputs="%(Identity).skip" DependsOnTargets="PrepareNUnitRunner;BuildNUnitTestAssemblies">
<Message Text="%(NUnitTestProjectsWithDependsOn.Identity):" />
<Message Text=" Depends on: %(NUnitTestProjectsWithDependsOn.DependsOn)" />
<MSBuild Projects="%(NUnitTestProjectsWithDependsOn.Identity)" Targets="%(NUnitTestProjectsWithDependsOn.DependsOn)" />
</Target>
<Target Name="_RunNUnitTestsOnly" Inputs="@(NUnitTestAssemblies)" Outputs="%(Identity).skip" DependsOnTargets="PrepareNUnitRunner;PrepareTeamCityVSTestAdapterPath;BuildNUnitTestAssemblies;_BuildNUnitTestsDependsOn">
<PropertyGroup>
<NUnitTestAssemblies>@(NUnitTestAssemblies -> '"%(Identity)"', ' ')</NUnitTestAssemblies>
</PropertyGroup>
<ItemGroup>
<_NUnitArguments Include='--teamcity' Condition="'$(UseTeamCityLogging)' == 'True'" />
<_NUnitArguments Include='--agents=$(NumberOfParallelAgents)' />
<_NUnitArguments Include='$(NUnitTestAssemblies)' />
</ItemGroup>
<PropertyGroup>
<_NUnitArgumentString Condition="'@(NUnitFilters)' != ''">@(_NUnitArguments, ' ') --where "@(NUnitFilters->'(%(Identity))', ' and ')"</_NUnitArgumentString>
<_NUnitArgumentString Condition="'@(NUnitFilters)' == ''">@(_NUnitArguments, ' ')</_NUnitArgumentString>
</PropertyGroup>
<ItemGroup>
<_DotNetTestArguments Include='--logger:teamcity --test-adapter-path:$(TeamCityVSTestAdapterPath)' Condition="'$(UseTeamCityLogging)' == 'True' And '$(TeamCityVSTestAdapterPath)' != ''" />
<_DotNetTestArguments Include='$(NUnitTestAssemblies)' />
</ItemGroup>
<PropertyGroup>
<_DotNetTestArgumentString Condition="'@(DotNetTestFilters)' != ''">@(_DotNetTestArguments, ' ') --filter "@(DotNetTestFilters->'(%(Identity))', ' & ')"</_DotNetTestArgumentString>
<_DotNetTestArgumentString Condition="'@(DotNetTestFilters)' == ''">@(_DotNetTestArguments, ' ')</_DotNetTestArgumentString>
</PropertyGroup>
<Exec Command="dotnet test $(_DotNetTestArgumentString)" Condition="'%(NUnitTestAssemblies.UseDotNetTest)' == 'True'" />
<Exec Command=""$(NUnitRunnerPath)" $(_NUnitArgumentString)" Condition="'%(NUnitTestAssemblies.UseDotNetTest)' != 'True'"/>
</Target>
<Target Name="RunNUnitTestsWithDotCover" Condition="'$(CoverageToolName)' == 'DotCover'" DependsOnTargets="_RunNUnitTestsWithDotCover">
<PropertyGroup>
<DotCoverMergedSnapshotPath>_DotCoverMergedSnapshot.dcvr</DotCoverMergedSnapshotPath>
</PropertyGroup>
<Exec Command='"$(DotCoverRunnerPath)" merge /Source="@(DotCoverSnapshots)" /Output="$(DotCoverMergedSnapshotPath)"' />
<Exec Condition="'$(DotCoverXmlReportPath)' != ''" Command='"$(DotCoverRunnerPath)" report /Source="$(DotCoverMergedSnapshotPath)" /Output="$(DotCoverXmlReportPath)" /ReportType=XML' />
<Exec Condition="'$(DotCoverHtmlReportPath)' != ''" Command='"$(DotCoverRunnerPath)" report /Source="$(DotCoverMergedSnapshotPath)" /Output="$(DotCoverHtmlReportPath)" /ReportType=HTML' />
</Target>
<Target Name="_RunNUnitTestsWithDotCover" Inputs="@(NUnitTestAssemblies)" Outputs="%(DotCoverSnapshot)" DependsOnTargets="PrepareNUnitRunner;PrepareTeamCityVSTestAdapterPath;PrepareDotCover;BuildNUnitTestAssemblies;_BuildNUnitTestsDependsOn">
<Message Text="DotCover + NUnit: %(NUnitTestAssemblies.Identity) -> %(NUnitTestAssemblies.DotCoverSnapshot)" />
<ItemGroup>
<_NUnitArguments Include='--teamcity' Condition="'$(UseTeamCityLogging)' == 'True'" />
<_NUnitArguments Include='"%(NUnitTestAssemblies.Identity)"' />
</ItemGroup>
<PropertyGroup>
<_NUnitArgumentString Condition="'@(NUnitFilters)' != ''">@(_NUnitArguments, ' ') --where "@(NUnitFilters->'(%(Identity))', ' and ')"</_NUnitArgumentString>
<_NUnitArgumentString Condition="'@(NUnitFilters)' == ''">@(_NUnitArguments, ' ')</_NUnitArgumentString>
</PropertyGroup>
<ItemGroup>
<!-- This does not work with dotCover: -->
<!-- <_DotNetTestArguments Include='--logger:teamcity "--test-adapter-path:$(TeamCityVSTestAdapterPath)"' Condition="'$(UseTeamCityLogging)' == 'True' And '$(TeamCityVSTestAdapterPath)' != ''" />-->
<_DotNetTestArguments Include='"%(NUnitTestAssemblies.Identity)"' />
</ItemGroup>
<PropertyGroup>
<_DotNetTestArgumentString Condition="'@(DotNetTestFilters)' != ''">@(_DotNetTestArguments, ' ') --filter "@(DotNetTestFilters->'(%(Identity))', ' & ')"</_DotNetTestArgumentString>
<_DotNetTestArgumentString Condition="'@(DotNetTestFilters)' == ''">@(_DotNetTestArguments, ' ')</_DotNetTestArgumentString>
</PropertyGroup>
<ItemGroup>
<_DotCoverCoverageArguments Include='"$(DotCoverConfigurationFile)"' />
<_DotCoverCoverageArguments Include='/Output="%(NUnitTestAssemblies.DotCoverSnapshot)"' />
<_DotCoverCoverageArguments Include='/TargetExecutable="$(NUnitRunnerPath)"' Condition="'%(NUnitTestAssemblies.UseDotNetTest)' != 'True'" />
</ItemGroup>
<PropertyGroup>
<_DotCoverCoverageArgumentString>@(_DotCoverCoverageArguments, ' ')</_DotCoverCoverageArgumentString>
</PropertyGroup>
<Exec Command=""$(DotCoverRunnerPath)" cover-dotnet $(_DotCoverCoverageArgumentString) -- $(_DotNetTestArgumentString)" Condition="'%(NUnitTestAssemblies.UseDotNetTest)' == 'True'" />
<Exec Command=""$(DotCoverRunnerPath)" cover $(_DotCoverCoverageArgumentString) -- $(_NUnitArgumentString)" Condition="'%(NUnitTestAssemblies.UseDotNetTest)' != 'True'" />
<Message Text="##teamcity[importData type='dotNetCoverage' tool='dotcover' path='%(NUnitTestAssemblies.DotCoverSnapshot)']" />
<ItemGroup>
<DotCoverSnapshots Include="%(NUnitTestAssemblies.DotCoverSnapshot)" />
</ItemGroup>
</Target>
</Project>