Background
We are slowly updating a very old application (based on "normal"
SqlCommandqueries and everything that comes with it) with some new code. To enhance stability and ease further development, we introduced NHibernate into the mix, along with good programming practices and what not.So now, whenever a new module (not that the application is actually modular, but lets call it that) needs a large enough update, we break out all functionality into the "new" world of NHibernate and create a facade for the old code, so it keeps working.
Setup
I am creating Unit Tests for the facades. For this, I created a base class that all unit test classes are inheriting from. This class, on TestInitialize
- creates the database schema using NHibernates "SchemaExport"
- creates a "legacy" schema that consist of all tables that are not yet mapped by Nhibernate, but are needed by the facades to work
Every TestClass (inheriting from the one above) has its own DataSet.sql which is executed on TestInitialize, which
- fills mapped Nhibernate tables with test specific data
- fills the legacy tables with test specific data
- fills a
testExecutionstable with input and expected output for each test run
The TestMethod of each TestClass then iterates over the testExecutions rows, creates the required objects (NHibernate), calls the facade it tests, and Asserts the returned data against what was defined in the testExecutions table.
Problem
The testing works fine, I get exactly the results I expect, but...
I have a big problem with this approach: Every test run visible in the test outputs is actually many many test executions. But from the outside, it just looks like a single test, even if the test itself actually runs the tested facade method many times over, with new data each time
I read about Data Driven Unit Tests and thought that it was literally exactly what I was already doing. So, instead of using my own things, I decided I should use that.
But the problem is: The TestContext.DataRow does obviously not know about NHibernate, so I don't actually get the objects required for testing, but a DataRow object with all data filled in the "old" way of Sql objects.
Is there a way to "teach" DataSource to return Nhibernate objects? Do I have to write my own DataSource attribute to accomplish this? How would that need to look?
Or is there another way
Is there a way to make my TestMethods to record the iteration over the testExecutions the same way a Data Driven test would do? So I don't have one Test, but the actual amount of tests run inside the method?