Skip to content

Commit

Permalink
Merge pull request #863 from nunit/testname
Browse files Browse the repository at this point in the history
Adding test name in console output
  • Loading branch information
OsirisTerje committed May 28, 2021
2 parents 1e1feba + d82ea00 commit 52d8342
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 36 deletions.
Expand Up @@ -95,10 +95,9 @@ private static MethodInfo TryGetSingleMethod(string assemblyPath, string reflect
#endif

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

var methods = type.GetMethods().Where(m => m.Name == methodName).Take(2).ToList();
return methods.Count == 1 ? methods[0] : null;
var methods = type?.GetMethods().Where(m => m.Name == methodName).Take(2).ToList();
return methods?.Count == 1 ? methods[0] : null;
}
catch (FileNotFoundException)
{
Expand Down
8 changes: 2 additions & 6 deletions src/NUnitTestAdapter/NUnit.TestAdapter.csproj
Expand Up @@ -28,14 +28,10 @@
<DisableHandlePackageFileConflicts>false</DisableHandlePackageFileConflicts>
</PropertyGroup>

<ItemGroup>
<Content Include="..\..\LICENSE.txt" Link="LICENSE.txt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" PrivateAssets="All" />
<PackageReference Include="nunit.engine" Version="3.12.0" />
<PackageReference Include="TestCentric.Metadata" Version="1.4.1" Aliases="TestCentric"/>
<PackageReference Include="nunit.engine" Version="3.12.0" />
<PackageReference Include="TestCentric.Metadata" Version="1.4.1" Aliases="TestCentric" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net35'">
Expand Down
40 changes: 23 additions & 17 deletions src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs
Expand Up @@ -93,8 +93,8 @@ internal static class NUnitXmlAttributeNames

public string AssemblyPath { get; private set; }

IAdapterSettings Settings { get; }
ITestLogger TestLog { get; }
private IAdapterSettings Settings { get; }
private ITestLogger TestLog { get; }

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

IEnumerable<NUnitDiscoveryTestCase> RunnableTestCases(bool isExplicit)
{
IEnumerable<NUnitDiscoveryTestCase> result;
if (isExplicit || !Settings.DesignMode)
result = TestRun.TestAssembly.AllTestCases;
else
result = TestRun.TestAssembly.RunnableTestCases;
return result;
}
IEnumerable<NUnitDiscoveryTestCase> RunnableTestCases(bool isExplicit) =>
isExplicit || !Settings.DesignMode
? TestRun.TestAssembly.AllTestCases
: TestRun.TestAssembly.RunnableTestCases;
}

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

private static void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement node)
private void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement node)
{
foreach (var child in node.Elements("test-suite"))
{
var type = child.Attribute(NUnitXmlAttributeNames.Type).Value;
var type = child.Attribute(NUnitXmlAttributeNames.Type)?.Value;
if (type == null)
{
TestLog.Debug($"ETF1:Don't understand element: {child}");
continue;
}

var className = child.Attribute(NUnitXmlAttributeNames.Classname)?.Value;
switch (type)
{
Expand Down Expand Up @@ -233,11 +234,16 @@ private static void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement
}
}

private static void ExtractTestFixtures(NUnitDiscoveryCanHaveTestFixture parent, XElement node)
private void ExtractTestFixtures(NUnitDiscoveryCanHaveTestFixture parent, XElement node)
{
foreach (var child in node.Elements().Where(o => o.Name != "properties"))
{
var type = child.Attribute(NUnitXmlAttributeNames.Type).Value;
var type = child.Attribute(NUnitXmlAttributeNames.Type)?.Value;
if (type == null)
{
TestLog.Debug($"ETF2:Don't understand element: {child}");
continue;
}
var className = child.Attribute(NUnitXmlAttributeNames.Classname)?.Value;
var btf = ExtractSuiteBasePropertiesClass(child);
switch (type)
Expand Down Expand Up @@ -366,8 +372,8 @@ public static NUnitDiscoveryTestCase ExtractTestCase(INUnitDiscoveryCanHaveTestC

private NUnitDiscoveryTestAssembly ExtractTestAssembly(XElement node, NUnitDiscoveryTestRun parent)
{
string dType = node.Attribute(NUnitXmlAttributeNames.Type).Value;
if (dType != "Assembly")
string dType = node.Attribute(NUnitXmlAttributeNames.Type)?.Value;
if (dType is not "Assembly")
throw new DiscoveryException("Node is not of type assembly: " + node);
var aBase = ExtractSuiteBasePropertiesClass(node);
var assembly = new NUnitDiscoveryTestAssembly(aBase, parent);
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/NUnitEngine/NUnitEventTestCase.cs
Expand Up @@ -59,7 +59,7 @@ public class NUnitEventTestCase : NUnitTestNode, INUnitTestCase, INUnitTestCaseP
public string ClassName => Node.GetAttribute("classname");
public string MethodName => Node.GetAttribute("methodname");

RunStateEnum runState = RunStateEnum.NA;
private RunStateEnum runState = RunStateEnum.NA;

public RunStateEnum RunState
{
Expand Down
18 changes: 12 additions & 6 deletions src/NUnitTestAdapter/NUnitEventListener.cs
Expand Up @@ -157,13 +157,19 @@ public void TestFinished(INUnitTestEventTestCase resultNode)
}

var result = _testConverter.GetVsTestResults(resultNode, outputNodes ?? EmptyNodes);
if (_settings.ConsoleOut == 1 && !string.IsNullOrEmpty(result.ConsoleOutput) && result.ConsoleOutput != NL)
if (_settings.ConsoleOut == 1)
{
_recorder.SendMessage(TestMessageLevel.Informational, result.ConsoleOutput);
}
if (_settings.ConsoleOut == 1 && !string.IsNullOrEmpty(resultNode.ReasonMessage))
{
_recorder.SendMessage(TestMessageLevel.Informational, $"{resultNode.Name}: {resultNode.ReasonMessage}");
if (!string.IsNullOrEmpty(result.ConsoleOutput) && result.ConsoleOutput != NL)
{
string msg = result.ConsoleOutput;
if (_settings.UseTestNameInConsoleOutput)
msg = $"{resultNode.Name}: {msg}";
_recorder.SendMessage(TestMessageLevel.Informational, msg);
}
if (!string.IsNullOrEmpty(resultNode.ReasonMessage))
{
_recorder.SendMessage(TestMessageLevel.Informational, $"{resultNode.Name}: {resultNode.ReasonMessage}");
}
}

_recorder.RecordEnd(result.TestCaseResult.TestCase, result.TestCaseResult.Outcome);
Expand Down
4 changes: 1 addition & 3 deletions src/NUnitTestAdapterTests/VsExperimentalTests.cs
@@ -1,5 +1,5 @@
// ***********************************************************************
// Copyright (c) 2018-2018 Charlie Poole, Terje Sandstrom
// Copyright (c) 2018 Charlie Poole, Terje Sandstrom
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand All @@ -24,8 +24,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using NSubstitute;
using NUnit.Framework;
Expand Down

0 comments on commit 52d8342

Please sign in to comment.