0

I'm currently doing some trainee work & looking for a bit of advice.

I've been set a pretty simple task of writing some unit tests for a service application in C#. The service mainly has methods which query and look up and SQL database for various things. I've been asked to write unit tests for the majority of these methods and other things like simply checking the connection and stuff. I've been told to keep it simple and probably just write the tests in a Console application. I'm wondering what the best way to go about this would be?

Would simply calling the methods from a console app with hardcoded input be suitable? Then just check what the output is & write whether is passes in the console? Or is this too simple and nasty?

5
  • Since you aren't asking specifically how to write code, but how to architect a solution, I would recommend asking this on programmers.stackexchange.com. Sep 24, 2012 at 20:03
  • I would just use MSTest, it will end up being less work than a console application and much more maintainable.
    – Maess
    Sep 24, 2012 at 20:04
  • You could use a test framework, like NUNit Sep 24, 2012 at 20:05
  • 1
    careful here you are talking about integration tests not unit tests!
    – MUG4N
    Sep 24, 2012 at 20:06
  • 1
    I suspect that the person who asked you to write the tests in a console application did so because they didn't understand the concept of unit tests (which typically avoid accessing outside resources like databases as much as possible). Pick an existing testing framework and learn it, use it, love it. You and your app will be much better off in the long run.
    – Jim Wooley
    Sep 24, 2012 at 20:20

1 Answer 1

2

You can run both MSTest and NUnit tests from the command line and in my opinion that would be far more preferable than writing your own test runner from scratch. Concentrate on writing quality tests, not the scaffolding required to execute them and deliver the results.

I would suggest it's as simple to do it "properly" as it is to craft your own solution.

Note though that tests connecting to the database are integration tests, not unit test.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.