1

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 ITables.
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?

2 Answers 2

2

How would I test INSERT and UPDATE 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 with Update 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.

Sign up to request clarification or add additional context in comments.

Comments

0

You could use the @ExpectedDatabase annotation with an appropriate assertMode

e.g.

@Test
@ExpectedDatabase(value = "result-data.xml")
public void testInsertion() {
    ...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.