views:

505

answers:

1

Hello, I'm using VS2008 to develop a project that I'm starting to test under Mono. There are a number of unit tests written using the VS unit test framework, is there a tool that will let me run these in Mono?

Thanks,

+2  A: 

Depending on the features that you're using it can be trivial or hard. You can use namespace/type aliasing to use another class library to do asserts, and the attributes. I've written console programs that run the tests manually - but of course I had access to the vs namespaces and assemblies.

For mono - my suggestion would be to use another testing system altogether as doing it yourself with system.reflection namepace to load the assembly, reflect the attributes and execute as you need to, will be tedious.

For example:

Pseudo code:

var assembly = loadAsembly(....)
foreach(type in assembly.types) {
 if(type is static class and had method with AssemblyInitialiseAttrubute)){
    InvokeTheMethod(method);
 }
}

foreach(type in assembly.types) {
 if(type is not class and had method with TestClass)){
    InvokeTheMethod(method);
 }
 foreach(method in type with ClassinitialiseAttribute)
}
... etc
Preet Sangha
Yes, thought I might end up rolling my own, but am still holding out for a readymade solution. Thanks.
bright
That turned out to be fairly straightforward, although I currently have a reference to the VS unit test assembly which defines the attributes (which I copy over to Mono, not very kosher.)
bright
why not define you're own attributes? then you get the best of both worlds?
Preet Sangha
you can make your reference disappear using the msbuild conditional attribute in the itemgroup entry for the reference in question - Condition='"$(am_using_mono)" != ""' - then in mono define the environment variable am_using_mono
Preet Sangha