|
A while ago I published an article and blogged on how to Unit Test the Data Layer. Recall that the basic approach is:
A common problem I keep facing is that these tests can take long to create, and longer to modify. Below are a few tips that I've been learning.
Creating the initialization script is usually tedious and time-consuming. One approach is to create or find a tool that takes a select statement and generates inserts from its result set (I built such a tool, but I can't release it because it's proprietary to my company, Ameripay). This lets you easily copy existing data for testing purposes.
I modified this tool to put tabs after each column, and place the insert and values sections on separate lines.
|
This lets me easily copy the text into Excel, which then automatically formats it in a tabular way that lines up column headers with contents, like so:
| insert into myTable( | myId, | col1, | col2 | ) |
| values( | '1', | 'abc', | 'def' | ) |
It's much easier to edit this way!
Therefore to maintain the data, I only need the raw SQL script itself - not some fancy generator/mapping tool or spreadsheet. I can now take the raw text and swap it between:
Two applications of this:
The sky is always the limit, but it's getting there.