المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Are tests ugly?



C# Programming
02-26-2010, 12:50 AM
I have written quite a few automated tests now with things like NUnit, and I find that they generally don't look very elegant. I find that code reuse is usually very difficult and code all ends up looking very similar. Books generally only show simple cases and in the real world with databases etc. things aren't quite so simple.

A good example of what I mean is database stuff. Every table works in pretty much the same way, but they all have different fields and types so you can't reuse much code. I find that most of my code looks like this:
SetupConnectionEtc();
SetupDataForTest();
DoSomething();
ReadTheDataAndCheckEverything();Although the first line probably isn't unique, all of the others usually are. So if your application uses 20 database tables then you will probably end up with 20 files containing a ReadTheDataAndCheckEverything() function, as well as some of the other ones.

What do people think? Am I doing something wrong or is there an easier way?