We all know the seven deadly sins – sloth, greed, envy, and so on. Well, today I found an eighth. I set up an automated system-test for a report generator we use at work. Basically, it will run the tool, and then interrogate the output to ensure it is correct (like a very large unit test). I wrote the test harness in the inbuilt test system in Visual Studio 2008, as I’m familiar with it.
Initially I set it up to call the “Main” method directly (it’s a console application), but quickly discovered that this wouldn’t work because the original developer had sprinkled Enviroment.Exit’s like they were fucking confetti. The effect of this was, of course, that whenever an exception was thrown, or the tool successfully completed (so, every single run, one way or the other), the test script would be killed so it would report as aborted. At this point, I looked like this:
The workaround I came up with in the end, as there was far too much code to re-engineer it, was to use the Process class to launch the app, and then check it’s return code. The big disadvantage here is that I can’t debug the code straight from the unit test.
I’m sure there’s some clever way to attach a debugger through code, but it would be better if it just didn’t use Environment.Exit in the first place.