jeudi 3 décembre 2015

Host Unit Testing Framework in our Application? (Nunit, xUnit, MsTest)

We are developing and maintaining a legacy winforms application. The application uses a domain model which ist quite separate from the GUI layer, but because of many dependecies, it is hard to unit test. At least we have a build and an installation script which we can use to automatically build and deploy the application.

Now if we could only have some automated system tests...

We came up with the following idea:

First, we could write our tests in script files like this:

public class Test
{
    public void TestSaveACustomer()
    {
        var c = new Customer();
        c.Name="Miller";
        Mapper.Save(c);
        Assert.IsTrue(c.CustomerId >0);
    }
}

Then, after building and deploying the application, we could run the scripts with a script runner that is baked into our application binary. We imagine we could use the following commandline

myapp.exe /runTest c:\myScript.cs

We could start to build our own Testing framework, wouldn't that be cool? ... er... no. It would be much less work if we could use an existing testing framework like nUnit, xUnit or MSTest from our application .

I guess I need to

  • Start a UnitTestRunner
  • Compile the Script
  • tell the runner to run the tests in the compiled script assembly.

I have no idea where to start, because I have only used UnitTests from VisualStudio.

Would that be possible with any existing testing framework? Which are the main classes I would use?

Aucun commentaire:

Enregistrer un commentaire