Would it be possible to have multiple [Property] attributes on a single xunit test method?
See original GitHub issueI’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:
- Created a year ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
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.