Skip to content

Commit 32012cf

Browse files
rogeralsingclaude
andcommitted
Use NUnit.Engine for test discovery
Use worker's NUnit.Engine-based discovery instead of reflection-based discovery. This properly expands parameterized tests (e.g., strict/ non-strict mode) and gives accurate counts upfront. - Spawn discovery worker before execution - Filter results using new TestFilter.Matches(fqn, displayName) overload - Revert dynamic total updates (no longer needed) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 8f4370c commit 32012cf

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

src/Asynkron.TestRunner/LiveDisplay.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class LiveDisplay
2121
private int _skipped;
2222
private int _hanging;
2323
private int _crashed;
24-
private int _seen; // Actual unique tests seen (handles parameterized expansion)
2524
private readonly HashSet<string> _running = new();
2625
private string? _lastCompleted;
2726
private string? _lastStatus;
@@ -33,14 +32,7 @@ public void SetTotal(int total)
3332

3433
public void TestStarted(string displayName)
3534
{
36-
lock (_lock)
37-
{
38-
_running.Add(Truncate(displayName, ContentWidth));
39-
_seen++;
40-
// Update total if we're seeing more tests than discovered (parameterized expansion)
41-
if (_seen > _total)
42-
_total = _seen;
43-
}
35+
lock (_lock) _running.Add(Truncate(displayName, ContentWidth));
4436
}
4537

4638
public void TestPassed(string displayName)

src/Asynkron.TestRunner/TestDiscovery.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ public bool Matches(DiscoveredTest test)
7373
return true;
7474
}
7575

76+
/// <summary>
77+
/// Matches against FQN and display name (for worker discovery results)
78+
/// </summary>
79+
public bool Matches(string fullyQualifiedName, string displayName)
80+
{
81+
// FQN format: Namespace.Class.Method
82+
if (Namespace != null && !fullyQualifiedName.Contains(Namespace, StringComparison.OrdinalIgnoreCase))
83+
return false;
84+
85+
if (Class != null && !fullyQualifiedName.Contains(Class, StringComparison.OrdinalIgnoreCase))
86+
return false;
87+
88+
if (Method != null && !fullyQualifiedName.Contains(Method, StringComparison.OrdinalIgnoreCase))
89+
return false;
90+
91+
if (DisplayName != null && !displayName.Contains(DisplayName, StringComparison.OrdinalIgnoreCase))
92+
return false;
93+
94+
return true;
95+
}
96+
7697
public bool IsEmpty => Namespace == null && Class == null && Method == null && DisplayName == null;
7798

7899
public override string ToString()

src/Asynkron.TestRunner/TestRunner.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,22 @@ public async Task<int> RunTestsAsync(string[] assemblyPaths)
4646

4747
AnsiConsole.MarkupLine($"[dim]Running tests in:[/] {Path.GetFileName(assemblyPath)}");
4848

49-
// Discover all tests upfront
50-
var filter = TestFilter.Parse(_filter);
51-
var discovered = await TestDiscovery.DiscoverTestsAsync([assemblyPath], filter);
52-
var allTests = discovered.Select(t => t.FullyQualifiedName).ToList();
49+
// Discover tests using worker (NUnit.Engine expands parameterized tests correctly)
50+
AnsiConsole.MarkupLine($"[dim]Discovering tests...[/]");
51+
List<string> allTests;
52+
await using (var discoveryWorker = WorkerProcess.Spawn())
53+
{
54+
var discovered = await discoveryWorker.DiscoverAsync(assemblyPath);
55+
56+
// Apply filter if specified
57+
if (!string.IsNullOrWhiteSpace(_filter))
58+
{
59+
var filter = TestFilter.Parse(_filter);
60+
discovered = discovered.Where(t => filter.Matches(t.FullyQualifiedName, t.DisplayName)).ToList();
61+
}
62+
63+
allTests = discovered.Select(t => t.FullyQualifiedName).ToList();
64+
}
5365

5466
if (allTests.Count == 0)
5567
{

0 commit comments

Comments
 (0)