xunit
xunit copied to clipboard
Support Parameterised Test Fixtures
XUnit should implement this feature https://docs.nunit.org/articles/nunit/writing-tests/attributes/testfixture.html#parameterized-test-fixtures in an XUnit way.
Specifically https://docs.nunit.org/articles/nunit/writing-tests/attributes/testfixturesource.html
Here is the my implementation using NUnit 3: https://github.com/Sauceforge/Saucery
I want to use utilise a similar mechanism in XUnit (which I believe it doesn't yet have, hence this feature request) to write a SauceryX NuGet package
@agray Can you please edit the body of this issue and describe the feature you're requesting (including proposed usage)? Thanks!
XUnit needs to support Parameterised Test fixtures that functionally work similarly to NUnit 3 parameterised test fixtures.
In order to assist with bringing this to fruition, it would help if you would take the time to summarise the key aspects that covers in the OP as Brad asked!
Perhaps there are some aspects of the NUnit impl you don't like? Perhaps you have insight into the critical bits of the feature that make it compelling to you? Can you give example use cases? Do you have a workaround you apply at present when confronted with the lack of this in xUnit?
In other words, I'm confident you can do better than "want copy of feature X, DM me when done KTHXBYE"
Closing for age. Please consider re-opening a new issue with a complete feature description. Thanks!
XUnit should implement this feature https://docs.nunit.org/articles/nunit/writing-tests/attributes/testfixture.html#parameterized-test-fixtures in an XUnit way.
Please reopen.
Thank you for reopening @bradwilson
I don't know what @agray has in mind, but... here's how I could see "parameterized test fixtures" being implemented in a way that improves upon NUnit's implementation:
+[FixtureInlineData(Platform.Ubuntu)
+[FixtureInlineData(Platform.Windows)
public class FileCreationTests : IClassFixture<MockPlatformEnv>
{
private MockPlatformEnv env;
[Fact] public void FileIsCreated { ... }
[Fact] public void FileHasGivenName { ... }
public FileCreationTests(MockPlatformEnv env)
{
this.env = env;
}
}
public class MockPlatformEnv
{
+ public MockPlatformEnv(Platform platform) { ... }
}
Collectively, all the tests within FileCreationTests would be first be ran with a shared instance of MockPlatformEnv which was constructed with Platform.Ubuntu. Then again, all tests would be ran with a shared instance of MockPlatformEnv which was constructed with Platform.Ubuntu.
The order in which these sets of tests run isn't of particular importance, imo
@qubitz. I was looking at Theory MemberData and Theory ClassData this morning. Unfortunately it is only at the individual test level. XUnit needs to be able to apply the same idea at the class level so that the IEnumerable set can be looped over for ALL tests rather than just one test.
Am I correct in my understanding that XUnit doesn't yet support this?
Correct, we do not support class-level data.
Correct, we do not support class-level data.
Currently yes, this feature is requesting that XUnit would.
yeah there's no support yet, something like what I proposed above would allow for class level data. Looks like we are going in a little bit of a circle here. Would my proposal solve the issue @agray? It builds upon the idea of XUnit's existing class fixtures, but does not exist yet.
@qubitz I need [FixtureMemberData(SomeClass)] on the class
Where SomeClass derives from IEnumerable
And XUnit loops over the IEnumerable for ALL facts and Theories in the class.
If SomeClass returns 5 rows and there are 10 Facts then 50 tests should be executed
If SomeClass returns 5 rows and there are 10 Facts And 1 Theory with 10 executions then 100 tests should be executed.
Okay cool, we're on the same page. FixtureInlineData was just the shortest example. I'd also like to expand the idea to encompass MemberData and ClassData concepts. @bradwilson what level of complexity would be involved to implement this feature? Is this within the scope of XUnit's purpose?
XUnit I understood had the weight of Microsoft behind it. Every other major unit test framework can do this. This is a massive gap in XUnit, IMO.
XUnit is supposed to have the weight of Microsoft behind it.
Says who? I work on this, alone, in my free time. I don't get paid for this.
Every other major unit test framework can do this. This is a massive gap in XUnit.
I'm not saying I will or won't do this feature, but "because everybody else does it" is not an argument that carries much weight with me. In point of fact, xUnit.net was designed to be explicitly different from the existing frameworks.
If everybody else does this, why don't you use everybody else? /shrug
(In case it's not clear: I have no tolerance for passive/aggressive demands on my personal time.)
Thanks for replying @bradwilson. Much appreciated.
If everybody else does this, why don't you use everybody else?
I do. I maintain the Saucery open source project. It is currently implemented against JUnit (SauceryJ) and NUnit (Saucery). I'd love to be able to implement it against XUnit (SauceryX). JUnit, NUnit and probably even more so, XUnit are the titans in the unit testing space.
I'm not saying I will or won't do this feature,
Thank you.
xUnit.net was designed to be explicitly different from the existing frameworks. And indeed it is. Using language features like constructors rather than [Setup] is a great approach and very clean.
I suppose all I am suggesting is that its a shame such a great framework doesn't yet have class level setup to apply to all tests in the class.
Kind Regards, Andrew
This feature would avoid having to modify thousands of unit tests that are Facts to become very ugly and repetitive Theories.
+1 on this. Let us know if you need help @bradwilson
Just adding a comment here so I get notifications. I am wanting to use xunit for UI tests with appium. The test code will all be the same, just need away to have multiple tests for each class/method.
(as we're triggering notifications... see the notifications button top right if you ever need this but you added some context so not necessarily saying you should delete your comment ... but maybe I should/will delte this one after you ack it)
I started this discussion around this idea and things I can do today. https://github.com/xunit/xunit/discussions/2897
But my comment before adds such minimal extra context so probably not worth keeping. But also, it does add some but I am in bed and deleting is extra work at midnight XD
Just adding a comment here so I get notifications. I am wanting to use xunit for UI tests with appium. The test code will all be the same, just need away to have multiple tests for each class/method.
Check out github.com/sauceforge/saucery.
Saucery.XUnit on NuGet.
Check out github.com/sauceforge/saucery
@agray what you have here is functionally similar to what I was expecting. On this test class you inherit from a base class that has a method that can initialize a fixture with the specified arguments.
A drawback of this solution is that each method within the test class is required to reinitialize the fixture which could be computationally expensive. Though I suppose it could be cached and diffed. Additionally, each method within the test class would require the same theory data attribute.
Regardless, thank you for taking the time to implement and share your workaround.