Skip to content

Commit d82ea00

Browse files
committed
Adding test name in console output
1 parent 1e1feba commit d82ea00

File tree

6 files changed

+41
-36
lines changed

6 files changed

+41
-36
lines changed

src/NUnitTestAdapter/Metadata/DirectReflectionMetadataProvider.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ private static MethodInfo TryGetSingleMethod(string assemblyPath, string reflect
9595
#endif
9696

9797
var type = assembly.GetType(reflectedTypeName, throwOnError: false);
98-
if (type == null) return null;
9998

100-
var methods = type.GetMethods().Where(m => m.Name == methodName).Take(2).ToList();
101-
return methods.Count == 1 ? methods[0] : null;
99+
var methods = type?.GetMethods().Where(m => m.Name == methodName).Take(2).ToList();
100+
return methods?.Count == 1 ? methods[0] : null;
102101
}
103102
catch (FileNotFoundException)
104103
{

src/NUnitTestAdapter/NUnit.TestAdapter.csproj

+2-6
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@
2828
<DisableHandlePackageFileConflicts>false</DisableHandlePackageFileConflicts>
2929
</PropertyGroup>
3030

31-
<ItemGroup>
32-
<Content Include="..\..\LICENSE.txt" Link="LICENSE.txt" />
33-
</ItemGroup>
34-
3531
<ItemGroup>
3632
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" PrivateAssets="All" />
37-
<PackageReference Include="nunit.engine" Version="3.12.0" />
38-
<PackageReference Include="TestCentric.Metadata" Version="1.4.1" Aliases="TestCentric"/>
33+
<PackageReference Include="nunit.engine" Version="3.12.0" />
34+
<PackageReference Include="TestCentric.Metadata" Version="1.4.1" Aliases="TestCentric" />
3935
</ItemGroup>
4036

4137
<ItemGroup Condition="'$(TargetFramework)' == 'net35'">

src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs

+23-17
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ internal static class NUnitXmlAttributeNames
9393

9494
public string AssemblyPath { get; private set; }
9595

96-
IAdapterSettings Settings { get; }
97-
ITestLogger TestLog { get; }
96+
private IAdapterSettings Settings { get; }
97+
private ITestLogger TestLog { get; }
9898

9999
public bool NoOfLoadedTestCasesAboveLimit => NoOfLoadedTestCases > Settings.AssemblySelectLimit;
100100
public IEnumerable<TestCase> CheckTestCasesExplicit(IEnumerable<TestCase> filteredTestCases)
@@ -163,15 +163,10 @@ public IList<TestCase> Convert(NUnitResults discoveryResults, string assemblyPat
163163
timing.LogTime("Converting test cases ");
164164
return loadedTestCases;
165165

166-
IEnumerable<NUnitDiscoveryTestCase> RunnableTestCases(bool isExplicit)
167-
{
168-
IEnumerable<NUnitDiscoveryTestCase> result;
169-
if (isExplicit || !Settings.DesignMode)
170-
result = TestRun.TestAssembly.AllTestCases;
171-
else
172-
result = TestRun.TestAssembly.RunnableTestCases;
173-
return result;
174-
}
166+
IEnumerable<NUnitDiscoveryTestCase> RunnableTestCases(bool isExplicit) =>
167+
isExplicit || !Settings.DesignMode
168+
? TestRun.TestAssembly.AllTestCases
169+
: TestRun.TestAssembly.RunnableTestCases;
175170
}
176171

177172
public NUnitDiscoveryTestRun ConvertXml(NUnitResults discovery)
@@ -192,11 +187,17 @@ private static NUnitDiscoveryTestSuite ExtractTestSuite(XElement node, NUnitDisc
192187
return ts;
193188
}
194189

195-
private static void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement node)
190+
private void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement node)
196191
{
197192
foreach (var child in node.Elements("test-suite"))
198193
{
199-
var type = child.Attribute(NUnitXmlAttributeNames.Type).Value;
194+
var type = child.Attribute(NUnitXmlAttributeNames.Type)?.Value;
195+
if (type == null)
196+
{
197+
TestLog.Debug($"ETF1:Don't understand element: {child}");
198+
continue;
199+
}
200+
200201
var className = child.Attribute(NUnitXmlAttributeNames.Classname)?.Value;
201202
switch (type)
202203
{
@@ -233,11 +234,16 @@ private static void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement
233234
}
234235
}
235236

236-
private static void ExtractTestFixtures(NUnitDiscoveryCanHaveTestFixture parent, XElement node)
237+
private void ExtractTestFixtures(NUnitDiscoveryCanHaveTestFixture parent, XElement node)
237238
{
238239
foreach (var child in node.Elements().Where(o => o.Name != "properties"))
239240
{
240-
var type = child.Attribute(NUnitXmlAttributeNames.Type).Value;
241+
var type = child.Attribute(NUnitXmlAttributeNames.Type)?.Value;
242+
if (type == null)
243+
{
244+
TestLog.Debug($"ETF2:Don't understand element: {child}");
245+
continue;
246+
}
241247
var className = child.Attribute(NUnitXmlAttributeNames.Classname)?.Value;
242248
var btf = ExtractSuiteBasePropertiesClass(child);
243249
switch (type)
@@ -366,8 +372,8 @@ private static NUnitDiscoveryParameterizedTestFixture ExtractParameterizedTestFi
366372

367373
private NUnitDiscoveryTestAssembly ExtractTestAssembly(XElement node, NUnitDiscoveryTestRun parent)
368374
{
369-
string dType = node.Attribute(NUnitXmlAttributeNames.Type).Value;
370-
if (dType != "Assembly")
375+
string dType = node.Attribute(NUnitXmlAttributeNames.Type)?.Value;
376+
if (dType is not "Assembly")
371377
throw new DiscoveryException("Node is not of type assembly: " + node);
372378
var aBase = ExtractSuiteBasePropertiesClass(node);
373379
var assembly = new NUnitDiscoveryTestAssembly(aBase, parent);

src/NUnitTestAdapter/NUnitEngine/NUnitEventTestCase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class NUnitEventTestCase : NUnitTestNode, INUnitTestCase, INUnitTestCaseP
5959
public string ClassName => Node.GetAttribute("classname");
6060
public string MethodName => Node.GetAttribute("methodname");
6161

62-
RunStateEnum runState = RunStateEnum.NA;
62+
private RunStateEnum runState = RunStateEnum.NA;
6363

6464
public RunStateEnum RunState
6565
{

src/NUnitTestAdapter/NUnitEventListener.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,19 @@ public void TestFinished(INUnitTestEventTestCase resultNode)
157157
}
158158

159159
var result = _testConverter.GetVsTestResults(resultNode, outputNodes ?? EmptyNodes);
160-
if (_settings.ConsoleOut == 1 && !string.IsNullOrEmpty(result.ConsoleOutput) && result.ConsoleOutput != NL)
160+
if (_settings.ConsoleOut == 1)
161161
{
162-
_recorder.SendMessage(TestMessageLevel.Informational, result.ConsoleOutput);
163-
}
164-
if (_settings.ConsoleOut == 1 && !string.IsNullOrEmpty(resultNode.ReasonMessage))
165-
{
166-
_recorder.SendMessage(TestMessageLevel.Informational, $"{resultNode.Name}: {resultNode.ReasonMessage}");
162+
if (!string.IsNullOrEmpty(result.ConsoleOutput) && result.ConsoleOutput != NL)
163+
{
164+
string msg = result.ConsoleOutput;
165+
if (_settings.UseTestNameInConsoleOutput)
166+
msg = $"{resultNode.Name}: {msg}";
167+
_recorder.SendMessage(TestMessageLevel.Informational, msg);
168+
}
169+
if (!string.IsNullOrEmpty(resultNode.ReasonMessage))
170+
{
171+
_recorder.SendMessage(TestMessageLevel.Informational, $"{resultNode.Name}: {resultNode.ReasonMessage}");
172+
}
167173
}
168174

169175
_recorder.RecordEnd(result.TestCaseResult.TestCase, result.TestCaseResult.Outcome);

src/NUnitTestAdapterTests/VsExperimentalTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ***********************************************************************
2-
// Copyright (c) 2018-2018 Charlie Poole, Terje Sandstrom
2+
// Copyright (c) 2018 Charlie Poole, Terje Sandstrom
33
//
44
// Permission is hereby granted, free of charge, to any person obtaining
55
// a copy of this software and associated documentation files (the
@@ -24,8 +24,6 @@
2424
using System;
2525
using System.Collections.Generic;
2626
using System.Linq;
27-
using System.Text;
28-
using System.Threading.Tasks;
2927
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
3028
using NSubstitute;
3129
using NUnit.Framework;

0 commit comments

Comments
 (0)