XUnit share context without constructor injection #2597
-
I am trying to share context between all tests. I've found this beautiful tutorial how it can be done through xunit. So I've created database fixture to be shared between all tests like the above tutorial said:
And:
And shared fixture looks like this:
So far, so good, it works perfectly. However, I have more than 300 classes and what I have to do is to write this constructor initialization in more than 300 classes of tests:
My question is how is it possible to avoid to write the above constructor in more than 300 classes of tests? Is it possible? Maybe is there more simpler way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You don't need to add the constructor if you don't need access to the fixture object from within the unit test. It will still be created appropriately. If you do need access to the fixture object, then there's no way around this today. Constructor injection is the only way to get access to fixture objects in v2. |
Beta Was this translation helpful? Give feedback.
You don't need to add the constructor if you don't need access to the fixture object from within the unit test. It will still be created appropriately.
If you do need access to the fixture object, then there's no way around this today. Constructor injection is the only way to get access to fixture objects in v2.