Skip to content

Commit 95f84db

Browse files
committed
Don't mark points to non test methods
1 parent fc548da commit 95f84db

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

Core/Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PackageReference Include="Microsoft.Build" Version="16.5.0">
2020
<ExcludeAssets>runtime</ExcludeAssets>
2121
</PackageReference>
22+
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
2223
<PackageReference Include="xunit.runner.utility" Version="2.4.1" />
2324
</ItemGroup>
2425

Core/Data/TestProjectData.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Runtime.Loader;
77
using System.Text;
88
using TestMyCode.CSharp.API.Attributes;
9+
using Xunit;
910

1011
namespace TestMyCode.CSharp.Core.Data
1112
{
@@ -58,8 +59,18 @@ private void FindPoints(Assembly assembly)
5859
{
5960
PointsAttribute? typeAttribute = type.GetCustomAttribute<PointsAttribute>();
6061

61-
foreach (MethodInfo methodInfo in type.GetMethods())
62+
foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Instance
63+
| BindingFlags.Static //xUnit allows static methods
64+
| BindingFlags.Public
65+
| BindingFlags.NonPublic)) //xUnit allows private methods
6266
{
67+
//TheoryAttribute inherits from FactAttribute
68+
FactAttribute? factAttribute = methodInfo.GetCustomAttribute<FactAttribute>();
69+
if (factAttribute is null)
70+
{
71+
continue;
72+
}
73+
6374
PointsAttribute? methodAttribute = methodInfo.GetCustomAttribute<PointsAttribute>();
6475
if (typeAttribute is null && methodAttribute is null)
6576
{

TestAssembly/TestPoints.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ namespace TestMyCode.CSharp.TestAssembly
99
[Points("1")]
1010
public class TestPoints
1111
{
12+
[Fact]
1213
[Points("1.3")]
1314
public void TestWithPoints()
1415
{
1516

1617
}
1718

19+
[Fact]
1820
public void TestWithoutPoints()
1921
{
2022

23+
}
24+
25+
#pragma warning disable xUnit1013 // Public method should be marked as test
26+
public void NotActuallyTestNoPoints()
27+
#pragma warning restore xUnit1013 // Public method should be marked as test
28+
{
29+
2130
}
2231
}
2332
}

Tests/Points/TestPoints.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ public TestPoints()
2020
[Theory]
2121
[InlineData(typeof(TestAssembly.TestPoints), nameof(TestAssembly.TestPoints.TestWithPoints), new[] { "1", "1.3" })]
2222
[InlineData(typeof(TestAssembly.TestPoints), nameof(TestAssembly.TestPoints.TestWithoutPoints), new[] { "1" })]
23+
[InlineData(typeof(TestAssembly.TestPoints), nameof(TestAssembly.TestPoints.NotActuallyTestNoPoints), null)]
24+
[InlineData(typeof(TestAssembly.TestPoints), nameof(TestAssembly.TestPoints.Equals), null)]
2325
public void ClassHasPoints(Type methodClass, string methodName, string[] expect)
2426
{
25-
HashSet<string> points = this.TestProjectData.Points[$"{methodClass.FullName}.{methodName}"];
27+
string key = $"{methodClass.FullName}.{methodName}";
2628

27-
Assert.Equal(points, expect);
29+
this.TestProjectData.Points.TryGetValue(key, out HashSet<string> methodPoints);
30+
31+
Assert.Equal(expect, methodPoints);
2832
}
2933
}
3034
}

0 commit comments

Comments
 (0)