question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Would it be possible to have multiple [Property] attributes on a single xunit test method?

See original GitHub issue

I’m thinking on the case when I detect an issue in one of my property tests, I usually copy the seed and add a new method OriginalTest_Regresion2 just to test that seed in the future, but the method just have to call the OriginalTest with the same parameters.

[MyProperty] // Inherits from PropertyAttribute to add some Arbitraries
public void OriginalTest(SomeTestType data, OtherTestType request)
{
    // ...
}

[MyProperty(Replay = "1234,5678")]
public void OriginalTest_Regression1(SomeTestType data, OtherTestType request)
{
    OriginalTest(data, request);
}

[MyProperty(Replay = "5678,1234")]
public void OriginalTest_Regression2(SomeTestType data, OtherTestType request)
{
    OriginalTest(data, request);
}

What I’m asking is the possibility to do the following:

[MyProperty]
[MyProperty(Replay = "1234,5678")]
[MyProperty(Replay = "5678,1234")]
public void OriginalTest(SomeTestType data, OtherTestType request)
{
    // ...
}

I know that xunit could impose some restrictions on having multiple test discoverer attributes on a single method. I’m just asking to know if it could be possible somehow.

PD: After all, InlineData on Theory does something similar to what I would need. Maybe more like:

[MyProperty]
[PropertyVariation(Replay = "1234,5678")]
[PropertyVariation(Replay = "5678,1234")]
public void OriginalTest(SomeTestType data, OtherTestType request)
{
    // ...
}

Just thinking outloud

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kurtschelfthoutcommented, Aug 2, 2022

@ploeh you are correct, that is the status quo for v2.x.

In 2.x it’s hard to implement because it needs an non-backwards compatible API change (or at least the obvious way to do it needs that, there’s probably workaround involving global state…)

In 3.x this feature exists (i.e. you can run just one test) https://github.com/fscheck/FsCheck/blob/fscheck3/src/FsCheck/Runner.fs#L503

0reactions
iskandersierracommented, Aug 3, 2022

Another option for the index, is to have an optional parameter on properties, like: int testCaseIndex, so that we can use conditional breakpoints on them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

xUnit and multiple data records for a test
xUnit won't allow you to use the TestData class, it only accepts an IEnumerable<object> and requires it to be static, but the benefit...
Read more >
Is it OK to have multiple asserts in a single unit test?
I don't think it's necessarily a bad thing, but I do think we should strive towards only having single asserts in our tests....
Read more >
Creating parameterised tests in xUnit with [InlineData], ...
In this post I describe how to create parameterised tests using xUnit's [Theory], [InlineData], [ClassData], and [MemberData] attributes.
Read more >
Are Multiple Asserts Bad in a Unit Test?
Multiple asserts are good if you are testing more than one property of an object simultaneously. This could happen because you have two...
Read more >
Shared Context between Tests
You can use the collection fixture feature of xUnit.net to share a single object instance among tests in several test classes. To use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found