views:

155

answers:

3

Hi All,

This is a very strange request for advice for which I truly feel there is no real answer. In my project I have archiving routines on various objects that have been consumed for logical calculations, I archive these items for the sake of audit trail and to check up on calculation errors or prove correctiveness at a later stage. I am working with Entity Framework and things are slightly different to perhaps your own project.

I consume the original object, modify it directly, create a clone of the modified item, revert the original item from store and save changes accordingly. An object is not reverted to original if never consumed by a calculation, in these instances, I save directly over that object along with the various relationships that exist with further objects.

This may sound long winded, but I assure you - it seems the easiest so far in terms of my workings with EF in my situation.

My trouble with these archiving routines is, that over time as I introduce further functionality - I sometimes, without knowing, break critical code to a point where I have to regression test the entire solution over, from beginning to end, to ensure that the archiving requirements remain intact.

Is there any unit test approach or automated methodology for testing these sorts of requirements. It would speed up deployment of packages cutting down on my own manual testing.

Any advice or links to simlar situations appreciated.

+1  A: 

The number one best practice for unit tests is just do it! Beyond that, I'd like to recommend xUnit Test Patterns: Refactoring Test Code by Gerard Meszaros.

Ewan Todd
Thanks Ewan, I'm going to do a bit more reading on unit testing to see if this is the correct approach for me. It's not so much a unit of code but more a process. The book you've recommended seems to be packed with information and worth a look into.
Microdot
+3  A: 

I think there are two pieces to this problem you are describing:

  1. First you need some unit tests that you can build which will represent technical requirements of the system. Think of the unit tests as the rules which you have set up to technically accomplish the goal that the end user desires. In this way, I would craft unit tests that you can feel confident will break if a technical assumption you had made about the system fails because of a code change. Remember to keep the unit tests at the unit level so that you don't have a large amount of dependencies interacting to fail a test. A unit test should test exactly one thing. If you do this, when you make code changes you can run all your unit tests and immediately know what assumptions you had made about the system which are now not being met.

  2. I would also set up some sort of integration functional tests which are automated. I think in your problem domain it would make sense to set up integrated tests which are similar to unit tests (you can use the same tool.) Here you will want to take bigger pieces of functionality, perhaps pipes which data flows through the system and test that the correct series of transformations occur on the data.

John Sonmez
Clear and precise Mr Sonmez. Thank you for your explination, it is appreciated. I've been reading a bit more on best practices re: unit testing and agree - keep things singular in terms of testing. For those who are interested, although old, the link is: http://msdn.microsoft.com/en-us/magazine/cc163665.aspx. The other half of my problem is indeed automation testing and have a good idea on how to achieve this using data for which I can predict correct output upon. Please keep the ideas coming guys / gals.
Microdot
+2  A: 

One best practice is to make sure the tests can be run in any order. You could separate the produce routines from the archive routines, perhaps by using "gold" data on the archive routing.

Brian Carlton
Thanks Brian, I'll keep this in mind during my development of these smaller type unit tests.
Microdot