What options are there for writing Unit Tests on code that performs mass database updates
I have code in a very old desktop application that I am converting to C#. It runs a billing cycle and I have a test database that performs the update on around 5000 rows of data.
I can take a copy of the database, run it with the desktop application and run it with my code and perform a compare with SQL EXCEPT to make sure my new code is producing exactly the same results as the the desktop code.
This is fine for running manually, but it would be nice to somehow automate this, and indeed to add it to our development environment so it can be run regularly as part of our suite of unit tests, together with various tests using different settings.
I'm not familiar with this sort of testing - I usually just run with very limited amounts of data where the unit test creates the data, runs the test, then deletes the data again, or just uses NSubstitute to simulate data persistence.
We use a Microsoft SQL Server database 2008 and later.
So any thoughts, suggestions, articles, ideas would be welcome.
I think there are few main points that you might be interested in:
How to construct data for Unit Tests
With 5000 rows (either in one or a few tables), creating data from scratch doesn't seem to be a good option. But since you are reinventing/refactoring your already-working functions, you might want to consider using a copy of the database --> clone data (and tables) before running Unit Tests --> run Unit Tests --> cleanup cloned data or rollback test database to original state.
Note that how your old desktop-based application connects to database could limit the options.
How to automate your old desktop-based application?
If your old desktop-based application can be separated from its business logic layers (let's call it BizLayer), and the UI layer does nothing but simply call function from BizLayer with user-specified parameters, then the easiest option is wrap your BizLayer into a class library to be used in Unit Tests (or just reference old desktop-based application if your BizLayer doesn't do any nasty thing with interactive desktop).
Otherwise you could consider using an Windows Automation tool like AutoIt.
How to compare the output?
With large amount of data, you could combine cloning tables when preparing test data, and then easily use SQL EXCEPT for comparing output from old desktop-based application and your new code.
You can also export output test data into Excel files and them compare them your self-created comparison utility or use a 3rd tool like WinMerge.
Hope that my 2 cents could give you some initials.