I’m working on a windows website where some errors appear randomly because of a locked web.config file. Apart from finding out who’s the culprit and taking it down, i’d like to test my code against these edge cases: for example in this situation, an exception is thrown and it makes my code use some default settings; had i noticed that, i would have made it keep a previous version of the settings.
Are there some tools that could let me test against this, for example by locking some files i configured, or deleting some files, etc? How do you test against these kinds of edge cases?
Abstract away the code that accesses the file. Have it implement an interface. Now create (or mock) an implementation of the interface that throws an exception. You should be able to use this implementation to test your code in the case of exceptions.
If you post some code, I can be more specific.