DbUnit @DatabaseTearDown annotation: how to delete only certain records? (the ones added with @DatabaseSetup annotation)

I am trying to delete only the records that I inserted using @DatabaseSetup annotation.

My test looks like this:

@Test
@DatabaseSetup("classpath:data-set.xml")
@DatabaseTearDown(value={"classpath:data-set.xml"}, type= DatabaseOperation.DELETE)
public void testSomething() throws Exception {

      

data set.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <person id="1" name="Joe"/>
</dataset>

      

Presumably the use of DatabaseOperation.DELETE means "Deletes the rows from the database table that match the rows from the dataset." But when I execute the test, it deletes all data in my table.

I think the problem is with the XML file format used for the pluck. I've tried using different formats:

first try in tear-down.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <person id="1"/>
</dataset>

      

second attempt at break. xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <person/>
</dataset>

      

And no matter what format is used, it always deletes all data in the table. I can't find any example of a format used for punching that doesn't just list the table name. In most of the examples, people seem to be using the same XML file for both install and break.

But that should be possible, no?

+3


source to share


1 answer


The records inserted into the database are not removed by annotation @DatabaseTearDown

, but @DatabaseSetup

. The reason is that DbUnit cleans up tables by default and then inserts test records. This can be prevented by using DatabaseOperation.INSERT

.



+5


source







All Articles