Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can create <strong>database proxy</strong> classes, making sure they are the only classes that talk to the real database. Use <strong>dependency-injection</strong> to unit test all your logic code without talking to the actual database. Create as <strong>few end-to-end tests as possible</strong> to make sure the proxies can read/write to the database correctly.</p> <p><strong>End-to-end tests are usually fragile by nature</strong>. So create as few of them as possible, and if you need to create a lot you can create an abstraction layer for setting up fixtures and assertions. <strong>Duplication in test cases</strong> is just as difficult to maintain as duplication in code.</p> <p><em>Working Effectively with Legacy Code</em> is a good start, and I recommend <em>xUnit Test Patterns</em>, which is basically the bible of unit testing with lots of good advice including a section on testing with databases.</p> <p><strong>Edit:</strong> TDD is all about isolating logic. What I mean is control flow statements, regular expressions, algorithms, math, should be outside your proxies where you can unit test them easily. You had 113 tests which makes me suspect there is logic that can be extracted and unit tested.</p> <p>If you are creating SQL commands, you can use the <code>Builder</code> pattern to verify the commands are created correctly, and if you need to change the SQL dialect, there is only one place to make the changes.</p> <p>Making your code testable may mean you need to refactor somewhat aggressively. The hard part will be determining how much is worth it, based on the importance and longevity of the project.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload