I am developing the acceptance test for a web service. The tests are driven through Specflow and using SQL Server CE as database. The service shares the DB with other applications and modules and uses some data created through one of those apps.
From the point of view of my product, there are two types of "data":
- Data that we only consume
- Data that we create/modify
Before running a test case, you set up the initial state of the database. For the consumed only data, the only way to initialise the data is inserting directly in the database. But for managed data we either can set the state directly in the DB, or do it as a user would do it, calling the API.
For example, I want to test that my method 'updateItem' updates correctly the price of the item to 'y'. To be able to execute this method I need to set up my database with an initial item with price 'x'. There are two ways of doing this:
- Set the state of the item directly in the database
- Call 'createItem'
The pros for the first method is that I only execute the method I want to test, so if the test fails, only fails for one reason. The cons would be that if in the future the state of the created item changes (adding a new field), I need to make that change in the initial state manually.
In the other hand, with the second method the pros and cons would be the opposite. The test could fail because 'createItem' failed, although some test frameworks would tell you that it was the set up what failed, not the actual test. But whatever changes occur in 'createItem', those changes are automatically included in your test and you don´t have to update the initial state manually.
Any advice is much appreciated.