I would like to write some integration test for my application. I wasn’t able to find some relevant information with examples on this subject so I’m asking here.
Let’s have a controller with a simple CRUD scenario.
There is a create method, edit method and delete method.
My question is how to design the test case.
I was thinking of two ways how to test it.
1.
- Test 1 Create item – just insert an item
- Test 2 Edit item – load the item from the first test and edit it
- Test 3 Delete item – delete the item used in Test 2 and 3.
In this case all tests are more like one big test case.
-
- Test 1 Create item – insert an item, check if it’s there and delete it.
- Test 2 Edit item – insert an item,load the item, edit it and delete the item.
- Test 3 Delete item – insert an item and delete the item
In this case the tests looks independent but they have some repetitive parts (inserts)
For the CRUD scenario you described, the test can be implemented with three separate database transactions and their associated assertions.
Step 1 – Insert an item
Step 2 – Assert that the item was inserted successfully
Step 3 – Edit the item
Step 4 – Assert that the item as edited successfully
Step 5 – Delete the item
Step 6 – Assert that the item was deleted successfully