NUnit Issues...
Everyone talks about Test driven development and Unit testing these days. And theoretically it isn’t quite bad actually. I have been reading about it since ages and the last time I finished my project, I had some time to delve over it and thought of actually implementing it in practice.
That’s when I got this opportunity to put this into practice. There was this on going internal project which was ongoing for quite some time and little bits and pieces were left out. I was told by a smart colleague of mine to work on it if I have time.
Well the 2 most important problems in working with NUnit is:
- You can’t access a configuration file to get information. If you are, since the configuration file is not loaded in memory during the running of the test cases, the information is lost and there is an exception. The classic example, accessing the database by picking up the connection string from web.config. The web.config is not loaded hence cannot be accessed. This ends up in failure to create the connection object and a NullReferenceException. That test fails and all related tests fail. Even though the tests are otherwise not supposed to fail.
- You can’t test the code on the UI layer. Event handling code is not supported by NUnit because when the tests run, the page is not loaded in memory.
I did some research on how to get around the problem. They say there is this NUnitAsp that can help you solve both the problems. It is an NUnit Add-in and lets you load the form and generate UI related tests. The only problem with it is that it access the IIS anonymously.
Now if you are using Windows authentication in your web application, you have to disallow anonymous access to the web application in a case like this you cannot use NUnitAsp because you will always get a 401 error.
Usually all the web applications developed at my work place use windows authenticated security. The company I work for work in the finance domain and security is an important issue. So the conclusion is NUnitAsp is out.
I think the NUnitAsp needs a little change. It should allow windows authentication. Should be able to pick up the current user login credentials and log in to the windows authenticated web application and run the test cases.