I am trying to implement ICollectionFixture for all my test in a visual studio solution. In the solution the devs have different service projects with different test projects. I am wanting to setup a startup method that runs once before all the test in the different projects. I came across ICollectionFixture but I am thinking it is only for different classes in the same project? Am I correct in understanding this? If I am correct and I can not use ICollectionFixture, what would be something I can use?
Asked
Active
Viewed 279 times
0
-
You should expand on what/why you feel you need this exact mechanism - often there are [different ways to meet a goal](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) which can be assisted with is explained. – Ruben Bartelink Feb 28 '19 at 22:28
-
@RubenBartelink My test need access to a local instance of postgres that is generated with a ps1 script. If that is not ran test fail. So currently we manually run the powershell script at the beginning of the day. Rather have this setup to run at the start of a test run so we do not have to manually remember to kick it off each morning. – rowdog_14 Mar 01 '19 at 15:24
1 Answers
0
xUnit does not provide a "before all tests" hook. In general the Class and Collection Fixture mechanisms are thus your only avenue as you've suggested.
The other is the use of static
variables holding cached versions of state.

Ruben Bartelink
- 59,778
- 26
- 187
- 249
-
What I ended up doing was just loading a ICollectionFixture for each test class project. Which is not the best but my method now only runs once for each test project instead of every test in the project. So instead of running over 500 times it runs 6. – rowdog_14 Mar 01 '19 at 15:38
-
In general, its best for each test to take responsibility for it's preconditions. While using a collectionfixture will ensure a single check and guarantee the precondition, it is at the expense of only one test class getting to use it at a time. If you instead do it as explicit code, then you need a way to make it run only once [this is one way to manage that](https://stackoverflow.com/questions/33872588/caching-the-result-from-a-n-async-factory-method-iff-it-doesnt-throw). Having said that, iif it works for you, it's all good – Ruben Bartelink Mar 01 '19 at 15:48
-
I am open to other factors...I will look into that reference you provided. So I want it as a one hitter quitter as mentioned in the original post and hopefully that reference can direct me to that goal. Thanks – rowdog_14 Mar 01 '19 at 16:59