Skip to content

Commit 80eeedf

Browse files
committed
Make PrintTestRunSummary task more resilient
- handle the nearly-empty `<assembly/>` elements xUnit sometimes writes to the results file nit: - use leading-underscore convention for private items in the `RunTests` target - make `@(_TestDLLsXunit)` items a bit easier to read
1 parent 4b30958 commit 80eeedf

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

Runtime.msbuild

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@
6868
<Exec Command='"$(NuGetExe)" restore "%(SolutionsToBuild.Identity)" -PackagesDirectory packages -NonInteractive -Verbosity quiet -ConfigFile "$(MsBuildThisFileDirectory)\.nuget\NuGet.Config"' />
6969
<!-- Pick the right Microsoft.Web.FxCop package to use and copy it to a standard location. -->
7070
</Target>
71-
71+
7272
<Target Name="BuildTools">
7373
<PropertyGroup>
7474
<FxCopProjectLocation>$(MsBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\</FxCopProjectLocation>
7575
<CustomFxCopRulesPath>$(MsBuildThisFileDirectory)packages\CustomFxCopRules</CustomFxCopRulesPath>
7676
</PropertyGroup>
77-
<MsBuild
77+
<MsBuild
7878
Condition=" '$(CodeAnalysis)' == 'true' "
79-
Projects="$(FxCopProjectLocation)\Microsoft.Web.FxCop.csproj"
79+
Projects="$(FxCopProjectLocation)\Microsoft.Web.FxCop.csproj"
8080
Properties="Configuration=Release;OutputPath=$(CustomFxCopRulesPath)" />
8181
</Target>
8282

@@ -98,17 +98,20 @@
9898

9999
<Target Name="RunTests" DependsOnTargets="CheckSkipStrongNames">
100100
<ItemGroup>
101-
<TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.dll;bin\$(Configuration)\test\*.Test.*.dll;bin\$(Configuration)\Test\NetCore\*.Test.dll;bin\$(Configuration)\Test\NetStandard\*.Test.dll" />
102-
<XunitProject Include="tools\WebStack.xunit.targets">
103-
<Properties>TestAssembly=%(TestDLLsXunit.FullPath);XmlPath=$(TestResultsDirectory)%(TestDLLsXunit.FileName)-XunitResults.xml</Properties>
104-
</XunitProject>
101+
<_TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.dll" />
102+
<_TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.*.dll" />
103+
<_TestDLLsXunit Include="bin\$(Configuration)\Test\NetCore\*.Test.dll" />
104+
<_TestDLLsXunit Include="bin\$(Configuration)\Test\NetStandard\*.Test.dll" />
105+
<_XunitProject Include="tools\WebStack.xunit.targets">
106+
<Properties>TestAssembly=%(_TestDLLsXunit.FullPath);XmlPath=$(TestResultsDirectory)%(_TestDLLsXunit.FileName)-XunitResults.xml</Properties>
107+
</_XunitProject>
105108
</ItemGroup>
106109

107-
<!-- Re-create the test results directory so that print summary doesn't run on old test results -->
110+
<!-- Recreate the test results directory so that print summary doesn't run on old test results. -->
108111
<RemoveDir Directories="$(TestResultsDirectory)" />
109112
<MakeDir Directories="$(TestResultsDirectory)" />
110113

111-
<MSBuild Projects="@(XunitProject)" BuildInParallel="$(TestInParallel)" Targets="Xunit" />
114+
<MSBuild Projects="@(_XunitProject)" BuildInParallel="$(TestInParallel)" Targets="Xunit" />
112115
</Target>
113116

114117
<Target Name="CheckSkipStrongNames" DependsOnTargets="RestoreSkipStrongNames">

tools/WebStack.tasks.targets

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,23 @@
178178
var assemblies = xml.Elements(XName.Get("assembly"));
179179
foreach (XElement assembly in assemblies)
180180
{
181-
int failures = Int32.Parse(assembly.Attribute(XName.Get("failed")).Value);
181+
XAttribute failed = assembly.Attribute(XName.Get("failed"));
182+
if (failed == null)
183+
{
184+
// Occasionally xUnit does not write information about test assembly completion.
185+
XAttribute name = assembly.Attribute(XName.Get("name"));
186+
Log.LogWarning(
187+
"No results in {0} for {1}.",
188+
testResultFile,
189+
name == null ? "unknown assembly" : name.Value);
190+
191+
continue;
192+
}
182193
183-
testsPassed += Int32.Parse(assembly.Attribute(XName.Get("passed")).Value);
194+
int failures = Int32.Parse(failed.Value);
184195
testsFailed += failures;
196+
197+
testsPassed += Int32.Parse(assembly.Attribute(XName.Get("passed")).Value);
185198
testsSkipped += Int32.Parse(assembly.Attribute(XName.Get("skipped")).Value);
186199
timeSpent += Decimal.Parse(assembly.Attribute(XName.Get("time")).Value);
187200

0 commit comments

Comments
 (0)