Skip to content

Commit 6c6bb80

Browse files
committed
2 parents 4205916 + 14769a9 commit 6c6bb80

14 files changed

Lines changed: 304 additions & 0 deletions

File tree

Issue3687/Issue3687.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<PropertyGroup>
11+
<PublishSingleFile>true</PublishSingleFile>
12+
<SelfContained>true</SelfContained>
13+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<!--<PackageReference Include="NUnit" Version="5.0.0-beta.1" />
18+
<PackageReference Include="NUnitLite" Version="5.0.0-beta.1" />-->
19+
20+
<PackageReference Include="NUnit" Version="4.6.1" />
21+
<PackageReference Include="NUnitLite" Version="4.6.1" />
22+
</ItemGroup>
23+
24+
</Project>

Issue3687/Issue3687.slnx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Issue3687.csproj" />
3+
</Solution>

Issue3687/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using NUnit.Framework;
2+
3+
Console.WriteLine("Hello, World!");
4+
5+
new NUnitLite.AutoRun().Execute(args);
6+
7+
[TestFixture]
8+
public class MyTests
9+
{
10+
[Test]
11+
public void Test1()
12+
{
13+
Assert.AreEqual(2, 1 + 1);
14+
}
15+
[Test]
16+
public void Test2()
17+
{
18+
Assert.IsTrue(true);
19+
}
20+
}

Issue5347/Directory.Build.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
</Project>

Issue5347/Directory.Packages.props

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
8+
<PackageVersion Include="NUnit" Version="4.6.1" />
9+
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
10+
<PackageVersion Include="NUnitLite" Version="4.6.1" />
11+
</ItemGroup>
12+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- For more information, see https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019 -->
3+
4+
<RunSettings>
5+
<RunConfiguration>
6+
</RunConfiguration>
7+
8+
<!-- Adapter Specific sections -->
9+
<!-- NUnit3 adapter, uncomment sections to set as appropriate, numeric, booleans, enums have their default values below, except RandomSeed -->
10+
<!-- For documentation, see https://docs.nunit.org/articles/vs-test-adapter/Tips-And-Tricks.html -->
11+
<NUnit>
12+
<DumpXmlTestDiscovery>true</DumpXmlTestDiscovery>
13+
<DumpXmlTestResults>true</DumpXmlTestResults>
14+
<PreFilter>true</PreFilter>
15+
<Where>test == MyTests.Test2</Where>
16+
</NUnit>
17+
</RunSettings>
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<IsPackable>false</IsPackable>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="..\Issue5347.Tests\Init.cs" Link="Init.cs" />
9+
<Compile Include="..\Issue5347.Tests\Tests.cs" Link="Tests.cs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
14+
<PackageReference Include="NUnit" />
15+
<PackageReference Include="NUnit3TestAdapter" />
16+
</ItemGroup>
17+
18+
</Project>

Issue5347/Issue5347.Tests/Init.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using NUnit.Framework.Interfaces;
2+
using System.Reflection;
3+
using NUnit.Framework;
4+
5+
[SetUpFixture]
6+
public class Init
7+
{
8+
[OneTimeSetUp]
9+
public void BeforeAllTests()
10+
{
11+
var assemblyContext = TestContext.CurrentContext.Test.Parent;
12+
foreach (var test in assemblyContext.Tests)
13+
{
14+
PrintTestDetails(test);
15+
}
16+
}
17+
18+
// Note that the tests are found on the second level here.
19+
private static void PrintTestDetails(ITest test)
20+
{
21+
if (test.Tests.Count > 0)
22+
{
23+
foreach (var child in test.Tests)
24+
{
25+
PrintTestDetails(child);
26+
}
27+
28+
return;
29+
}
30+
31+
TestContext.Progress.WriteLine($"TestName: {test.Name}");
32+
TestContext.Progress.WriteLine("Properties");
33+
foreach (var key in test.Properties.Keys)
34+
{
35+
var values = test.Properties[key];
36+
var joinedValues = string.Join(", ", values.Cast<object?>().Select(v => v?.ToString() ?? "<null>"));
37+
TestContext.Progress.WriteLine($"Key: {key}: Value: {joinedValues}");
38+
}
39+
40+
TestContext.Progress.WriteLine("Attributes:");
41+
if (!string.IsNullOrWhiteSpace(test.ClassName) && !string.IsNullOrWhiteSpace(test.MethodName))
42+
{
43+
var method = FindMethod(test.ClassName, test.MethodName);
44+
if (method != null)
45+
{
46+
foreach (var attribute in method.GetCustomAttributes(inherit: true))
47+
{
48+
TestContext.Progress.WriteLine($"Attribute: {FormatAttribute(attribute)}");
49+
}
50+
}
51+
}
52+
}
53+
54+
private static string FormatAttribute(object attribute)
55+
{
56+
var parts = attribute.GetType()
57+
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
58+
.Where(p => p.CanRead && p.GetIndexParameters().Length == 0 && p.Name != nameof(Attribute.TypeId))
59+
.Select(p =>
60+
{
61+
var value = p.GetValue(attribute);
62+
if (value is System.Collections.IEnumerable enumerable && value is not string)
63+
{
64+
var values = enumerable.Cast<object?>().Select(v => v?.ToString() ?? "<null>");
65+
return $"{p.Name}=[{string.Join(", ", values)}]";
66+
}
67+
68+
return $"{p.Name}={value ?? "<null>"}";
69+
});
70+
71+
return $"{attribute.GetType().FullName} ({string.Join(", ", parts)})";
72+
}
73+
74+
private static MethodInfo? FindMethod(string className, string methodName)
75+
{
76+
var type = Type.GetType(className);
77+
if (type == null)
78+
{
79+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
80+
{
81+
type = assembly.GetType(className);
82+
if (type != null)
83+
{
84+
break;
85+
}
86+
}
87+
}
88+
89+
return type?.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
90+
.FirstOrDefault(m => m.Name == methodName);
91+
}
92+
93+
[OneTimeTearDown]
94+
public void AfterAllTests()
95+
{
96+
}
97+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<IsPackable>false</IsPackable>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="NUnit" />
9+
</ItemGroup>
10+
11+
</Project>

Issue5347/Issue5347.Tests/Tests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using NUnit.Framework;
2+
3+
[TestFixture]
4+
public class MyTests
5+
{
6+
[Test]
7+
public void Test1()
8+
{
9+
Assert.Pass();
10+
}
11+
12+
[Category("ExampleCategory")]
13+
[Test]
14+
public void Test2()
15+
{
16+
Assert.Pass();
17+
}
18+
19+
[Property("Whatever", 42)]
20+
[Category("ExampleCategoryTwo")]
21+
[Test]
22+
public void Test3()
23+
{
24+
Assert.Pass();
25+
}
26+
}
27+
28+
[TestFixture]
29+
public class MyNonTests
30+
{
31+
[Test]
32+
public void Test1()
33+
{
34+
Assert.Pass();
35+
}
36+
37+
[Category("ExampleCategory")]
38+
[Test]
39+
public void Test2()
40+
{
41+
Assert.Pass();
42+
}
43+
44+
[Property("Whatever", 42)]
45+
[Category("ExampleCategoryTwo")]
46+
[Test]
47+
public void Test3()
48+
{
49+
Assert.Pass();
50+
}
51+
}

0 commit comments

Comments
 (0)