Today I tried to switch the project with integration tests from maven to gradle. Everything worked perfectly, except that I have a serious problem with testng.
The project uses hibernate / JPA2 to access the database and has several tests that depend on the persistence unit in the / resources / META -INF / persistence.xml test. When I run the test suite with gradle, everything works fine. But when I run xml (or any test class on its own) from eclipse, it seems like it is trying to use main / resources / META-INF / persistence.xml.
Since I do most of my work using TDD, I really need to run / debug tests from eclipse. When I add a persistence block to the persistence.xml file, it works (it even gets some other resources from the "test" directory). This would be a workaround, but I really don't like the idea of ββadding test resources to "main / resources"
The 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:
The generated classpath file is as follows:
<?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 to combine everything into a bin folder and makes no distinction between the main and the test, like the .classpath file created by maven.
source share