今天我尝试将集成测试从maven切换到gradle.一切都很好,除了我有一个严重的问题与testng.
该项目使用hibernate / JPA2进行数据库访问,并且有一些依赖于test / resources / Meta-INF / persistence.xml中的持久性单元的测试.当我使用gradle运行测试套件时,一切正常.但是当我从eclipse运行xml(或任何测试类)时,它似乎尝试使用main / resources / Meta-INF / persistence.xml.
因为我使用TDD完成了大部分工作,所以我真的需要从eclipse运行/调试测试.当我将持久性单元添加到生产persistence.xml时,它可以工作(它甚至可以从“test”目录中获取一些其他资源).这将是一种解决方法,但我真的不喜欢将测试资源添加到“主要/资源”的想法
当我使用maven中的旧pom.xml导入它时,同一项目工作正常.
的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'
}
}
更新:
生成的类路径文件如下所示:
它似乎将所有内容合并到bin文件夹中,并且不区分main和test,就像maven生成的.classpath文件一样.