I am writing API integration tests using Xunit (c#).
I would like to get authentication tokens only once, and reuse them for all test classes.
Collection fixtures provide a solution for doing that, but that solution comes with a significant limitation. The test classes have to be part of the same collection, which means the tests in different classes will not be executed in parallel.
I'm curious if there is an obvious solution I'm not seeing to reuse the token but still have the tests executing in parallel. The alternatives are:
- authenticate for each test class (adding execution time, and possibly issues with multiple sessions for the same user)
- manage the lifetime of the token, using environment variables, for example. authenticate once to get the token, reuse the token if we have one and it is not expired.
Thanks