Reputation: 13587
How would I test INSERT
and UPDATE
operations using DB unit?
I am using a fixtures data xml for testing read operations.
Does it mean that test case would insert/update a row in xml itself? If yes, does DBUnit provides any utility to work with xmld?
Already test methods which tests if table returns one record or multiple records. In these read cases testing is being done by comparing ITable
s.
I am not sure what assert in case of create operation. Row count?
Same question goes with Update
operation. What should a test case assert after doing an update?
Upvotes: 1
Views: 2234
Reputation: 413
You could use the @ExpectedDatabase
annotation with an appropriate assertMode
e.g.
@Test
@ExpectedDatabase(value = "result-data.xml")
public void testInsertion() {
...
}
Upvotes: 0
Reputation: 3582
How would I test
INSERT
andUPDATE
operations using DB unit?
On INSERT
, verify the row count is +1 and run a SELECT
searching for the inserted record.
On UPDATE
, verify that the updated record doesn't match the old record by running a SELECT
before and after UPDATE
.
I am using a fixtures data xml for testing read operations
Does it mean that test case would insert/update a row in xml itself?
No. DbUnit reads the XML file and creates a snapshot of it in memory. Your inserts and updates are done in memory so the XMLs are never modified.
I am not sure what assert in case of create operation. Row count?
Same question goes withUpdate
operation. What should a test case assert after doing an update?
See the answer to question 1.
Also use http://dbunit.sourceforge.net/ for references.
Upvotes: 2