Daily Usage Issues

Problems with testing static service

Started by Stanislaw on 4,079 views

Hello!
A some of my tests using 3rd party library with static initialization of its service. So this service have an Init method with some arguments.
But I need to use it with a separate set of arguments for each test. When I running tests (even in non-parallel mode) I receive an error from random test (for each test set running) about that service is already initialized.
I understand that this case, may be, not related to NCrunch, but any answer or recomendation how to use fully separate static resource for each test will be highly appreciated.

P.S. I use XUnit
Hi, thanks for posting.

If I understand this problem correctly, you wish to isolate each individual test within its own process, as the execution of a test will 'fix' this service into a state where it cannot be reinitialised inside the same test process and cannot be changed.

Applying the Isolated attribute to these tests should allow you to work around this by forcing the NCrunch engine to place each of the tests inside its own process. Note that this will cause considerable loss in performance.

In case I haven't understood the problem correctly, I recommend having a read up on how NCrunch's test environment is different from other test runners. If the problem is being caused by a state or sequence related issue in the NCrunch test environment, it's worth being familiar with this.

Post a reply

Log in to reply.