I am having problems with my unit tests (NUnit) run with ReSharper. I have no problem executing each test individually, nor all tests in the project. Problems start when I execute all tests in the solution. Same tests are running perfectly fine executed with NUnit Adapter and VS Unit Test Explorer. I've managed to established, that tests are failing on accessing config file. Changing methods responsible to read values to hard coded and I am having no problems, but that is not a solution to the problem. I could create separate class, just to read config values, but I thought it is perfectly fine to get them through the method within the class (mvc controller). I have been trying to find the answer how to cure those problems, as it sounds a bit silly to avoid using config file - that's the sole purpose of that file in the first place.
1
votes
How to create a Minimal, Complete, and Verifiable example of what you have tried so far. That way people can use it to reproduce the problem and give much better answers.
– Nkosi
I know that the best way is to provide example, but in here it would mean entire solution. Running each test on its own won't generate error. Moving method responsible for reading from config file to separate class and mocking it latter cures the error, but doesn't answer the problem in multiple test filing in accessing config file
– Gutek
Pull the configs you need into a global variable at test initialize and then have all the tests that need them use when needed. It could be that multiple access to the config file is locking the file. The reason for minimal example was to see how you access config to confirm is file is being locked. At any point are you writing to config file?
– Nkosi
I am not writing to config file at any point. I am just going with ConfigurationManager.AppSettings["keyName"] I've went through my projects and I think I got to the bottom of the problem. ReSharper(dotCover) is managing config file access well within one project. It is struggling to do so, when more than one project are accessing config file taking first in, first serves. If reading from the file is finished in time, there is no error. I have no option, just to move config access to a separate class and mock it in tests. @Nkosi - thanks for your help
– Gutek
1 Answers
1
votes
Are you running tests in multiple projects? If so, check ReSharper's "Use separate AppDomain for each assembly" in ReSharper → Options → Unit Testing. There's an optimisation that will load multiple assemblies into the same AppDomain, but that means there can be only one config file, and it might be the wrong one. Using a separate AppDomain means each assembly will get its own config file.