views:

112

answers:

2

I'm trying to set up some unit tests for an existing compact framework class library. However, I've fallen at the first hurdle, where it appears that the test framework is unable to load the types involved (even though they're both in the class library being tested)

Test method MyLibrary.Tests.MyGenericClassTest.MyMethodTest threw exception: System.MissingMethodException: Could not load type 'MyLibrary.MyType' from assembly 'MyLibrary, Version=1.0.3778.36113, Culture=neutral, PublicKeyToken=null'..

My code is loosely:

public class MyGenericClass<T> : List<T> where T : MyType, new()
{
    public bool MyMethod(T foo)
    {
        throw new NotImplementedException();
    }
}

With test methods:

    public void MyMethodTestHelper<T>()
        where T : MyType, new()
    {
        MyGenericClass<T> target = new MyGenericClass<T>();
        foo = new T(); 
        expected = true;
        actual = target.MyMethod(foo);
        Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void MyMethodTest()
    {
        MyMethodTestHelper<MyType>();
    }

I'm a bit stumped though, as I can't even get it to break in the debugger to get to the inner exception, so what else do I check?

EDIT this does seem to be something specific to the Compact Framework - recompiling the class libraries and the unit tests for the full framework, gives the expected output (i.e. the debugger stops when I'm going to throw a NotImplementedException).

+1  A: 

Try the following - Create a console application and try doing whatever you are doing in the unit test. If that also doesnot work then there is some other issue. If that works there is a problem with the test.

Prashant
Compiling everything (I'm not unit testing any UI here) for the full framework works.
Rowland Shaw
A: 

Apparently, when unit testing a compact framework application, the .Net framework is not automatically deployed.

So instead you have to debug (which will deploy the framework automatically) an application on the device emulator that you intend to use for unit testing. You can cahnge whihc device emulator image is used for unit tests by double clicking on the 'SmartDeviceTestRun1.testrunConfig' solution item - the image to use is on the 'Hosts' tab

Rowland Shaw