Testing a Monotouch app with NUnit in MonoDevelop 2.4
I'm new to both Monotouch and Monodevelop. Trying to get started with NUnit and I'm having a lot of trouble -- none of the sketchy references I can find on line seem to match what I'm seeing in the UI (MonoDevelop 2.4 on Mac OS 10.6). I've tried:
- Adding an "NUnit assembly test collection" project to my solution.
- Adding an "Empty MonoTouch Project" project to my solution, and then adding the NUnit assemblies to it, and adding my main proje开发者_开发知识库ct as a reference.
- Adding a C# "Empty Project" to my solution, and adding NUnit, MonoTouch, and my own project as references. This produces a build error complaining that "'[test project name].exe' does not contain a static 'Main' method suitable for an entry point."
(1) produces a strange sort of project to which I can only add assemblies -- no references and certainly no tests.
(2) and (3) behave pretty much identically:
- First, a build error complaining that there's no static 'Main' method. I can fix this by changing the compile target to "Library" in the Build -> General project options.
- Next, when I try to run the tests (from the Unit Testing tab), it says it's running them using the "Debug|iPhoneSimulator" configuration.
- The Test Results panel shows this "running tests" message, and never any other output.
- The counts stay at "Tests: 0 Failed: 0 Ignored: 0".
Clearly I'm doing something wrong here, but what am I supposed to be doing?
Just for grins, here's my test.
using System;
using NUnit.Framework;
namespace mynamespace
{
[TestFixture]
public class NavItemTest
{
[Test]
public void TestAll()
{
Assert.AreEqual(4, NavItem.all().Count);
}
}
}
In case you missed it, there is now a NUnitLite runner available for MonoTouch which is designed to work for UI agnostic code and executed on devices (or simulator).
See: .NET Unit test runner for iOS
Have written up a few details on what we have found to be best practice so far. You can find it here: http://ben.phegan.name/index.php/2011/02/28/monotouch-and-unit-testing. Would be happy to hear other ways of doing this.
Short answer:
- Add NUnit project to normal solution
- Add MonoTouch assemblies as references
- Write tests, avoiding testing anything that uses monotouch.dll (design patterns to abstract this stuff).
- Win!
I had the same problem:
This produces a build error complaining that "'[test project name].exe' does not contain a static 'Main' method suitable for an entry point."
Fixed by going into Project -> [Project name] Options -> Build General. Changed Compile Target to Library. I hadn't made a Main-method class yet, but will probably later; so then I'll change back.
精彩评论