Question

My Junit tests use DBUnit and they run fine when run from Eclipse. However, running the same tests with Maven fails one test with:

integrity constraint violation: foreign key no action

I have tried running that test and the entire set of tests from eclipse GUI ("run as JUnit test") several times in a row and they never fail - but from Maven they do fail.

I use @DatabaseSetup for each test, but is it enough to really reset the database? I also thought Maven might run the tests in parallel so I tried setting forkMode to "always" for Surefire plugin in my pom.xml, but it didn't change anything.

Was it helpful?

Solution 2

Your are using the annotation @DatabaseSetUp from spring-test DBUnit for the database initialization. You should use the annotation @DatabaseTearDown too.

From the spring-test DBUnit documentation :

The @DatabaseTearDown annotation can be used to reset database tables once a test has completed. As with @DatabaseSetup the annotation can be applied at the method or class level. When using @DatabaseTearDown use the value and type attributes in the same way as @DatabaseSetup.

OTHER TIPS

I had a similar Problem refering to encoding used in the JVM during the maven tests.

I added following to my pom.xml:

<plugins>
    ...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <junitArtifactName>junit:junit</junitArtifactName>
            <encoding>UTF-8</encoding>
            <inputEncoding>UTF-8</inputEncoding>
            <outputEncoding>UTF-8</outputEncoding>
            <argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                -Dfile.encoding=UTF-8</argLine>
        </configuration>
    </plugin>
</plugins>

See also herer http://carlobertoldi.wordpress.com/2012/03/12/maven-unit-tests-and-those-funny-characters/

This solved my problems

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top