Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have found myself in a situation to write integration tests, but I didn't execute the tests against the development database since it was a subject of change. Since we used scrum methodology with sprints that lasted for two weeks, we were able to adopt the following approach:</p> <ol> <li>At the end of each sprint we would make test database that matches the schema of the development database. In most of the cases this database would be restored on the test db server before each test executed, and it would be dropped after the test has finished.</li> <li>Fill the test database with predictable set of data, that would not be a subject of change, except for the tests that need to change the data.</li> <li>Configure out test projects to execute against the test database.</li> </ol> <p>The tests that we wrote were separated in two parts.</p> <ol> <li>Tests that only perform select queries against the database.</li> <li>Tests that perform insert, update, delete queries against the database.</li> </ol> <p>Above mentioned approach allowed us to always know what to expect after each test has executed. We used <code>MSTest</code> framework to write our test and used its abilities to execute logic before and after each test, or before and after each set of tests. Below code applies to the tests that perform only select queries. </p> <pre><code>[TestClass] public class Tests_That_Perform_Only_Select { [ClassInitialize] public static void MyClassInitialize() { //Here would go the code to restore the test database. } [TestMethod] public void Test1() { //Perform logic for retrieving some result set. //Make assertions. } [TestMethod] public void Test2() { //Perform logic for retrieving some result set. //Make assertions. } [ClassCleanup] public static void MyClassCleanup() { //Here would go logic to drop the database. } } </code></pre> <p>This way the tests would execute against predictable set of data and we would always know what to expect. Restoring and dropping of the database would be performed once per test class which would speed up executing of the tests.</p> <p>For the tests that perform changes in the database, restoring and dropping of the database would be mandatory before each test executes, since we didn't want our next test to execute against a database that have unknown state because we wouldn't know what to expect. Here is a code sample for that scenario:</p> <pre><code>[TestClass] public class Tests_That_Perform_Insert_Update_Or_Delete { [TestInitialize] public void MyTestInitialize() { //Here would go the code to restore the test database. } [TestMethod] public void Test1() { //Perform logic. //Make assertions. } [TestMethod] public void Test2() { //Perform some logic. //Make assertions. } [TestCleanup] public void MyClassCleanup() { //Here would go logic to drop the database. } } </code></pre> <p>In this scenario the test database is restored and dropped before and after each test. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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