|
Copyright 2005 Randy Charles Morin
Part of the KBCafe Blog Network.
|
I use NUnit a lot. In fact, I doubt many have written more NUnit tests than I. I think I've written about ten thousand tests. I love the entire idea of regressive unit testing. That's one reason I believe my software is less buggy than most. Unfortunately, NUnit is extremely buggy. Fortunate that it is used by very technical people, because if you wrote software this buggy for mundane users, then you'd likely have no users at all. With each version of NUnit, thousands of bugs are fixed and thousands more are introduced. I just upgraded my NUnit to the latest 2.2.9 and of course, hundreds of tests are broken. Here's a simple code fragment they broke.
using System;
namespace TestHarness
{
[NUnit.Framework.TestFixture()]
public class UITests
{
[NUnit.Framework.Test]
public void SurfHomepage()
{
System.Windows.Forms.WebBrowser browser
= new System.Windows.Forms.WebBrowser();
browser.Navigate("http://www.r-mail.org");
while (browser.ReadyState !=
System.Windows.Forms.WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
}
}
}
}
What the NUnit team did was hardcode NUnit to use the MTA apartment thread, which no longer works with the .NET 2.0 WebBrowser object that requires STA. If you run this test, then you get the following error.
TestHarness.UITests.SurfHomepage : System.Threading.ThreadStateException : ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
Another problem with NUnit is that its horribly documenting. Searching for a solution to this problem was extremely difficult. A dozen of red herrings before I found two threads that vaguely identified the solution. Which I'll document better here.
The solution is to create a .config file for your tests. Follow these steps.
If you are using the NUnit console instead of the NUnit GUI, then local the .config file in the same folder as your test DLL and rename it accordingly.
Hi,
I am a novice user of NUNIT. I went thru the docs provide at NUNIT site but wasnt of much help for me. I want to test an interface kind of product written in C , COM, ATL, MFC using NUNIT. The product syncs some data from Outlook and a CRM product.
1. How to test such product in NUNIT? 2. Does NUNIT allows integration testing? If yes, how? 3. How to I use outlook's PST files in NUNIT? What language should be used to write the tests?
Thanks in advance.
Regards,
Vijay
Thanks, after considering other posts on this same topic, this is the one that actually worked!
[assembly:RequiresMTA]