Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

XUnit, Memberdata
Anders Juul
#1 Posted : Wednesday, November 26, 2025 8:17:18 AM(UTC)
Rank: Member

Groups: Registered
Joined: 11/21/2020(UTC)
Posts: 14
Location: Denmark

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Hi Remco,

I'd like to use Memberdata and see them in Test Window. Resharper displays the two scenarios just fine, but NCrunch Shows only "Kata" and from test output, it seems like it only runs BaseCasePostgres (last of the two).

Can I do anything to see the scenarios in test window?

BR, Anders

---
using Sait.VagtplanV2.Configuration;
using Sait.VagtplanV2.TestData;
using Xunit.Abstractions;

namespace Sait.VagtplanV2.Aspire.Tests;

[Collection("Integration Tests")]
public class IntegrationTestKata : IntegrationTestBase
{
public IntegrationTestKata(ITestOutputHelper output) : base(output)
{
}

[Theory]
[MemberData(nameof(ScenarioData.All), MemberType = typeof(ScenarioData))]
public void Kata(Scenario scenario)
{
var defaultCtsToken = scenario.DatabaseType == DatabaseType.Mssql ? NoTimeoutCts.Token : DefaultCts.Token;

Given(Output, DateTimeProvider, scenario.DatabaseType, defaultCtsToken)
//
.Then.TimeAdministration.Is.Healthy.And.Calculation.Is.Healthy
.With.Date20250901.As.Current.Day
//
.When.One.Duty.In.Week1.Is.Send.To.TimeAdministration
.Then.Result.Is.Success
//
.With.Date20250908.As.Current.Day
//
.When.Calculation.Of.Week1.Is.Requested
.Then.Result.Is.Success.And
.Then.Calculation.Database.For.Test.Tenant.Has.One.Calculations
//
.When.Updated.Duty.Is.Send.To.TimeAdministration
.Then.Result.Is.Success
//
.With.Date20250915.As.Current.Day
//
.When.Calculation.Of.Week2.Is.Requested
.Then.Result.Is.Success.And
.Then.Calculation.Database.For.Test.Tenant.Has.Two.Calculations
//
.Finally.Print.Summary();
}
}
public record Scenario(string Name, DatabaseType DatabaseType);
public static class ScenarioData
{
public static IEnumerable<object[]> All
{
get
{
yield return new object[]
{
new Scenario("BaseCaseMssql", DatabaseType.Mssql)
};

yield return new object[]
{
new Scenario("BaseCasePostgres", DatabaseType.Postgres)
};
}
}
}
Remco
#2 Posted : Wednesday, November 26, 2025 11:28:43 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,427

Thanks: 1008 times
Was thanked: 1353 time(s) in 1256 post(s)
Hi, thanks for posting.

Xunit rolls up the cases for this test (on instruction from NCrunch) because they are built using a user-defined type declared on their signature, which introduces significant complexity and risks when transferring them from the test discovery domain into the runtime environment.

NCrunch then has an additional constraint where tests themselves can only be created during discovery, not during execution. This differs from the normal VS test adapters that can simply add dummy tests at runtime to hold the results that are discovered late in the cycle.

To avoid these test cases from being rolled up, you'll need to make sure your ScenarioData uses primitive types only (such as String or Int), since these types are very simply for the system to transfer between domains. The alternative is to specify the test statically using inlinedata instead.

You'll find that when the test cases are rolled up like they are, they'll both still be run, but the results will be reported from both cases inside the same test. This naturally means that a failure from either of them will be reported as a failure of the rolled-up test.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.026 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download