Please consider adding modular fixtures in v3 roadmap #2181
-
Hello. Being long time user of xunit I can't help to see how limiting current fixtures are in xunit. The main issues in current fixtures implementation in xunit are:
Those aren't mine ideas of course. It's from pytest (and pytest took that from other testing frameworks if I'm not mistaken). Just look how simple it is. You want fixture that runs only once per test session? No problem - just declare it somewhere and test framework will find it and will handle life scope management for you:
And you want to use it in particular test method? No problem - just add it to method parameter - test framework automatically injects instance for you:
And if you need to use some fixture inside other fixture - that's right, just add it as new parameter and test framework will do everything else:
There are a lot more in pytest fixtures that xunit can implement too. But please consider at least adding a simple way to declare and use fixtures - without CollectionDefinition and constructor injection. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I don't understand this scope concept you've introduced here. What's a "session"?
Is your suggestion that you would decorate the fixture class with the fixture type? Because I'm not a fan of that. That's the wrong place for that information to live. How would you create a fixture that has generalized re-use, but is used in various ways (sometimes class fixture, sometimes collection fixture)? Given that this feature exists today as-is, I'd really like to see more public feedback before flipping the model on its head in a way that would break existing users (both their code and their notion of how the feature is supposed to work).
There is a generalized IoC feature request in the 3.0 pipeline. Might be worth pointing out on that issue what you're looking for: #1738 |
Beta Was this translation helpful? Give feedback.
-
In any case, maybe we can use both models? |
Beta Was this translation helpful? Give feedback.
-
Hi @MichaelLogutov, I cannot agree with you more. Honestly I do not understand how it is possible that people developping / using xUnit does not see how much the fixtures dependency addition (the fact that a fixture A may depend on a fixture B and that the test framework automatically generate the test cases, etc.) is making by itself pytest litterally most powerful than xUnit. The boilerplate required to write a test is far too high. Also, indeed, the fact that the syntax is totally different for what xUnit calls "Class Fixture" (implenting an interface) vs "CollectionFixture" (this time a tag with a string as name + a new empty class?) is extremely weird. The "official" way of combining fixture in xUnit is by making manually another class aggregating the 2 fixtures... how insane is that. |
Beta Was this translation helpful? Give feedback.
I don't understand this scope concept you've introduced here. What's a "session"?
Is your suggestion that you woul…