views:

117

answers:

6

If I'm not mistaken, NUnit is the de-facto standard for unit testing, but I've just downloaded it, wrote a simple test, and then apparently I have to fire up the GUI and load my .exe assembly, which simply failed.

I tried editing

C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\nunit.exe.config

As suggested in this question, but that didn't work either, so I tried downloading the nunit source code and compiling it in vs2010, but it doesn't even compile. Says punit.framework.dll could not be found. That solution says "does not contain a definition for AllTestsExecuted", so I'm getting a little frustrated here. You'd think there would be an easy-to-use-and-get-running framework for .net 4, no?

So my question is, how do I either get NUnit working, or is there another framework that will cause me less agony?

+4  A: 

Hi there.

You don't have to use the NUnit GUI to run your tests. You can use TestDriven.NET from within Visual Studio. Also, if you happen to be using Resharper, that has a unit test runner which works with NUnit also.

Cheers. Jas.

Jason Evans
ReSharper it is! I had it, but it wasn't installed...didn't feel a need for it (til now, anyway).
Mark
+1  A: 

If you're not doing anything out of the ordinary, I recommend Microsoft's Unit Testing Framework. I find it's VS integration too easy to even worry about NUnit. I agree NUnit seems to be the defacto standard, but if you're looking for something quick and easy. Microsoft's way is the easiest for a typical Visual Studio programmer IMHO.

Steve Danner
I don't see `Microsoft.VisualStudio.TestTools.UnitTesting` under the `Add Reference > .NET`... where is it?
Mark
For .NET 4, you actually use Microsoft.VisualStudio.QualityTools.UnitTestFramework located at C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll. The easiest thing to do is to just add a new project, and there's a subcategory of "test" which contains only the Test Project project template.
Steve Danner
A: 

NUnit is infact very simple to use, so I would say that it's more likely that you are making a mistake somewhere, not the software.

Make sure you follow this guide.

  • Ensure that you have the [TestFixture] and [Test] attributes in the correct places and all the relevant assemblies referenced.
  • Make sure that you are loading the correct dll in the NUnit GUI.

If its the GUI that is the issue, you can use Resharper's unit testing feature in stead.

rmx
It's the GUI that throws the error when I try loading my assembly. That's the guide that I was following.
Mark
A: 

If you use Visual Studio 2010, you can use MSTest. Just click CTRL + ALT + R and it will run your tests and show the results in Visual Studio itself.

That same test-runner will also work for NUnit, if I am not mistaken.

devoured elysium
A: 

I am not a C# programmer (fortunately ;-) ) but I've heard good things about xUnit. Tests can be run pretty much however you want (command line, GUI, Visual Studio integration, and more) and it looks reasonable simple to use.

alpha123
+1  A: 

For NUnit's GUI test runner, make sure you've selected the right framework version. Its in the "File" menu. If your test or any dependencies are 32-bit be sure you're running the 32bit version of the test runner.

Testdriven.net is a better test runner, but I like using NUnit's GUI runner too at times.

Frank Schwieterman
All I see is "New", "Open" and "Exit". Everything else is grayed out. Considering the "Open" part fails, I never even get a chance to choose a runtime.
Mark
Sounds like a x86/x64 mismatch, though that hasn't happened to me in awhile not sure what it looked like.
Frank Schwieterman
Yeah..could be, can NUnit even run in 64-bit mode?
Mark
There are separate binaries. nunit.exe is for 64bit, nunit-x86.exe is for 32bit.
Frank Schwieterman