Wednesday, November 26, 2008

Asp.net unit tests with nunit - config file

I have been trying to get more into testing lately. I work for a company that isn't really a development shop and I have never been exposed to proper testing methods in real life. So it has been up to me and my teammates to get a test environment setup and working without running up a huge bill.

We started with AutomatedQA's TestComplete product, which is very nice and helps us automate the macro type tasks.

I recently discovered that Visual Studio has builtin support for auto generating a good portion of Unit tests. Unfortunately the MSTest.exe file isn't stand alone. Since we really don't want to buy another license just to run unit tests I decided to check out NUnit which seemed to advertise exactly what we needed.

After a bit of work and learning I got some basic unit tests passing in NUnit. Then I tried to create tests for some of our database method calls. That's when things started blowing up. The error seemed to stem from the methods being unable to find the web.config file.

Reading around a little it looks like since I was running things in NUnit .NET wasn't looking for a config file with the name web.config. After taking half a dozen incorrect guesses based on various blog posts, I grabbed the good old tool File Monitor from sysinternals.com

I used that to figure out that it was looking for a file called unittests.config. I made a copy of my web.config file, renamed it to the desired name, and placed it in the folder where the nunit process was looking.

Now things are working much better, I still have a few bugs to workout, but I am no longer getting the config file error.

As a side note, in the NUnit GUI, under the Project/Edit menu item there is a configuration setting called "Configuration File Name" set to unittests.config. I have a strong hunch that setting controls the name of the file it is looking for. I did try and play with that setting earlier, however nunit kept throwing errors since the file didn't exist so I gave up; might have to look into it again.

No comments:

Post a Comment

Please leave your thoughts, I love hearing what you got out of the post. Spam comments will be removed.