Today I tried to switch an project with integration tests from maven to gradle. All worked fine except I have a serious problem with testng.
The project uses hibernate/JPA2 for database access and has a couple of tests that depend on a persistence unit in the test/resources/META-INF/persistence.xml. When I run the test suite using gradle all works fine. But when I run the xml (or any test class by itself) from eclipse it seems that it tries to use the main/resources/META-INF/persistence.xml.
Because I do most of my work using TDD, I realy need to run/debug tests from eclipse. When I add the persistence unit to the production persistence.xml it works (it even gets some other resources from the "test" dir). It would be a workaround, but I realy don't like the idea of adding test resources to "main/resources"
Same project works fine when I import it using the old pom.xml from maven.
build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.7
version = '0.1'
jar {
manifest {
attributes 'Implementation-Title': 'md', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'com.google.guava:guava:14.0.1'
compile 'org.hibernate:hibernate-entitymanager:4.2.2.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
testCompile 'ch.qos.logback:logback-classic:1.0.13'
testCompile 'org.testng:testng:6.8.5'
testCompile 'org.dbunit:dbunit:2.4.9'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'org.easytesting:fest-assert-core:2.0M10'
testCompile 'org.hsqldb:hsqldb:2.2.9'
}
test {
useTestNG(){
suites 'src/test/resources/testng.xml'
}
}
Update:
Generated classpath file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
<classpathentry kind="output" path="bin"/>
</classpath>
It seems it merges all into the bin folder and doesn't differentiate between main and test like the .classpath file generated by maven.