0

I've got a big windows service application. It performs actions on a time bound basis. Sometimes I need to be able to use some of it's functionality in isolation from the rest of the application. Currently I've got a battery of 'unit tests' which call into various sources and perform the desired functionality. My problem is these are not unit tests, they are the way we're exposing the API. If we run all the unit tests in the project, we'll be damaging some of our production data.

My question is how do I go about accessing some of the functionality of the application without unit testing? I was thinking of perhaps something like an interpreter over the top of it where you can call various parts of the functionality, but am not really that sure where to start.

An example of a unit test in our code will be:

[TestMethod]
public void TransferFunds()
{
    int accountNumberTo = 123456;
    int accountNumberFrom = 654321;
    var accountFrom = Store.GetAccount(accountNumberFrom);
    var accountTo = Store.GetAccount(accountNumberTo);
    double amountToTransfer = 1000;
    DateTime transactionDate = new DateTime(2010,01,01);
    Store.TransferFunds(accountFrom, AccountTo, amountToTransfer, transactionDate);
    var client = BankAccountService.Client();
    client.Contribute(accountNumberTo, amountToTransfer, transactionDate);
    client.Contribute(accountNumberFrom, amountToTransfer, transactionDate);
}

How can we move this out of unit tests, but still have the ability to run code like this?

Anish Patel
  • 705
  • 3
  • 8
  • 19

1 Answers1

0

Your setup sounds very dangerous. I would create separate console applications for your different needs. I would also remove recommend that you remove all unittests that endangers your production data. Having that sort of unittests is just down-right bad!

Morten
  • 3,778
  • 2
  • 25
  • 45
  • Agreed, but wouldn't having separate console applications for the hundreds of functions we would want to expose be a maintenance nightmare? The dangerousness of the unit tests is why I want to get that sort of code out of the unit tests, you never know when someone doesn't know not to run the unit tests and breaks everything! – Anish Patel Feb 28 '11 at 11:23
  • If you have hundreds of functions, the maintenance nightmare is there either way. If you do proper unit tests of your functionality, you can asume that everything is well until a test fails. – Morten Feb 28 '11 at 11:40