3

I'm just starting out with unit testing in C#.
I have been reading about unit testing for a long time now, and I've already been playing around with NUnit, but this is the first time that I actually try to write real tests for real code.

But my problem is:
I'm having a hard time to come up with things that I can actually test.

The project I want to test is a conversion library (to convert lists of POCOs to ADO Recordsets).

So far, I've come up with only two things to test:

  • if the recordset exists at all (not Null, not empty)
  • if the content of each field is the same (--> if RS!Foo == POCO.Foo)

So, my questions are:

  • What else can I test when my code just converts A to B?
  • Or is this project too small / too simple / not a good example to write more than a few meaningful unit tests for?
Christian Specht
  • 35,843
  • 15
  • 128
  • 182

3 Answers3

3

There are quite a few things to test. I would also suggest thinking about and potentially verifying:

  • Private fields of POCO don't map through correctly
  • Invalid entries in the list throw exceptions correctly
  • Recordset length is correct
  • Inheritance in POCO is handled as desired (ie: base class members map through as expected)
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
1

Add a conversion test case where you know the exact input and output. Then test that the code produces that answer exactly.

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
  • @JimMischel -- actually, no, one very good test case *is* a very good unit test. But I think you meant that one test case doesn't make a very good test *suite*. Agreed. But this is just to suggest one way, out of many, that he could test the code. And it will also double as a regression test, in case he makes future changes. – Matt Fenwick Nov 01 '11 at 16:18
0

Try the Pex tool from Microsoft. It generates Unit tests after analyzing your code. Just a quick install of Visual studio plugin. Then Right click the class/method you want to test and in the context menu get Pex to generate all the possible code paths for you.

Chaitanya
  • 5,203
  • 8
  • 36
  • 61