Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You say that you don't want to use an ORM, but I choose to disregard that in my answer. Sorry :)</p> <h3>How to populate</h3> <p>I prefer inserting data into the database using the same operations that a user would. That is, if I need an order for a product in the database, I create the product using the admin interface, let a user create an account using the public interface and have that user place an order.</p> <p>This doesn't have to be done by clicking buttons in the actual UI, but preferably using an underlying abstraction of the UI.</p> <p>Benefits:</p> <ul> <li>The database will have the same state as when executed for real, not the state <em>you think</em> it will have</li> <li>If you need to make changes, e.g. to the schema, you only have to change the production code</li> <li>More features are covered by the tests</li> <li>The database is populated only with data needed for this perticular use case</li> <li>The test are easier to read (it's not easy to read insert scripts)</li> </ul> <p>Drawbacks:</p> <ul> <li>It's slower</li> <li>Does't work well if you need <em>a lot</em> of data (which is rare)</li> </ul> <p>I've only needed a large amount of data for tests once. For that I created my own declarative domain specific language with which I could specify the necessary data in a (<a href="http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx" rel="nofollow">verbatim</a>) string inside my test. Then I wrote a tool that parsed the data and inserted it into the database.</p> <h3>Clean the database</h3> <p>There are several ways to clean the database: re-create the database; delete all data; execute the test in a transaction and make a rollback... My faviourite, though, is not to clean the database. For every test I create a new user and a new product (using the example from above). I don't have to clean the database and still the tests won't interfere with each other. Also, I will have the data around after the test if I need to inspect it.</p> <p>Hope it's somewhat helpful even though it's not really an answer to your question.</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