tags:

views:

381

answers:

3

I've developed a large base of unit tests for my company's application, and dev would like to hand my unit tests over to our support department to help them debug customer installation problems. I wrote my unit tests using mstest, so support would have to install Visual Studio on a customer's machine if they wanted to use my tests out of the box, which is the wrong thing to do, obviously. I have looked into using mstest without VS at the command prompt, but hacking the registry on a customer's system to make it think VS is installed isn't workable either.

To get around this I planned on compiling my mstests for nunit using the information in this post . However, after compiling with NUnit enabled, and adding my test assembly dll to the NUnit runner, I get the error message "This assembly was not built with any known framework."

Has anyone done this and has tips/tricks to get this running? Or is this the entirely wrong way to go about solving this problem? Thanks.

+1  A: 

I'm going to go with your second thought on this "Or is this the entirely wrong way to go about solving this problem".

To solve this problem easily and not confuse your support department I would recommend creating a little command-line wrapper around the test class. You can write the command-line tool yourself, or if you prefer you can do the following:

using CSharpTest.Net.Commands;
static void Main(string[] args)
{
    MyTest testClass = new MyTest();
    // optional: testClass.MySetupMethod();
    new CommandInterpreter(testClass).Run(args);
}

Just build the above code as a command-line exe in a new project referencing your test assembly and CSharpTest.Net.Libary.dll. The namespace CSharpTest.Net.Commands is defined in the CSharpTest.Net.Libary.dll assemby from this download.

Essentially the above code will crawl your test class (named MyTest in the example above) and expose all the public methods as commands that can be executed via the command line. By default it provides help output and sets the Environment.ExitCode on failure. If you want to get fancy you can decorate your tests with any of the following:

public class MyTest
{
    [System.ComponentModel.DisplayName("rename-this-function")]
    [System.ComponentModel.Description("Some description for tech-support")]
    [System.ComponentModel.Browsable(true | false)]
    public void TestSomeFunction()
    { ... }
}

(And yes I acknowledge I am shamelessly plugging my own code a wee-bit :)

csharptest.net
Interesting. I've gone down this a bit since yesterday, whipping up a small console app that used reflection to call the test methods in my class, but ran into problems with TestContext and the class initialization methods. Looks like you build your initializers yourself per test run?
Sharon
Ahh, no I forgot about MsTest's weird initialization dependencies. I think they did it intentionally to force you to keep using MsTest :) Anyway, can you break your dependencies on the MsTest specific stuff? If not, I would have to retract my original recommendation and suggest you write a command-line utility apart from the tests. Just keep it automated in the build in parallel with the tests to ensure it continues to work.
csharptest.net
+1  A: 

My concern would be someone adding a unit test (or integration test disguised as a unit test) which you inadvertently run against your customer database. Of course I'm making assumptions such as you having a database, but it seems a risky approach unless you can be sure that your tests are non-destructive, now and in the future.

Do you have logging in your application? That's the traditional way to help support, and there are many tools out there to help you.

Si
My plan was to give a subset of the tests to support that were explicitly designed to be non-destructive. As far as logging...I agree that would probably be preferable. Don't know that I can convince support or the dev leads of that though.
Sharon
A: 

You're not the only one. Take a look here.

http://www.shunra.com/shunrablog/index.php/2009/04/23/running-mstest-without-visual-studio/

Dave Jellison
Thanks. I think that doing that much to a customer server though probably wouldn't be advisable. And there would be serious licensing concerns with Visual Studio.
Sharon