Tôi đang cố thêm Gradle (1.4) vào dự án hiện có có nhiều bộ thử nghiệm. Kiểm tra đơn vị tiêu chuẩn nằm ở src/test/java
đã chạy thành công, nhưng tôi gặp sự cố khi thiết lập tác vụ để chạy kiểm tra JUnit nằm ở src/integration-test/java
.Thêm bộ kiểm tra bổ sung vào Gradle
Khi tôi chạy gradle intTest
Tôi nhận được một số lỗi cannot find symbol
cho các lớp học trong src/main
. Điều này khiến tôi tin rằng các phụ thuộc không được thiết lập chính xác. Làm thế nào để thiết lập intTest
để nó sẽ chạy thử nghiệm tích hợp JUnit của tôi?
build.gradle
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_6
sourceSets {
integration {
java {
srcDir 'src/integration-test/java'
}
resources {
srcDir 'src/integration-test/resources'
}
}
}
dependencies {
compile(group: 'org.springframework', name: 'spring', version: '3.0.7')
testCompile(group: 'junit', name: 'junit', version: '4.+')
testCompile(group: 'org.hamcrest', name: 'hamcrest-all', version: '1.+')
testCompile(group: 'org.mockito', name: 'mockito-all', version: '1.+')
testCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')
integrationCompile(group: 'junit', name: 'junit', version: '4.+')
integrationCompile(group: 'org.hamcrest', name: 'hamcrest-all', version: '1.+')
integrationCompile(group: 'org.mockito', name: 'mockito-all', version: '1.+')
integrationCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')
}
task intTest(type: Test) {
testClassesDir = sourceSets.integration.output.classesDir
classpath += sourceSets.integration.runtimeClasspath
}
chi tiết: Gradle 1,4
Giải pháp: tôi đã không được thiết lập classpath biên dịch cho các thiết lập tích hợp mã nguồn thử nghiệm (xem dưới đây) . Trong mã tôi, tôi thiết lập các đường dẫn lớp biên dịch để sourceSets.test.runtimeClasspath
vì vậy mà tôi không có sự phụ thuộc trùng lặp cho "integrationCompile"
sourceSets {
integrationTest {
java {
srcDir 'src/integration-test/java'
}
resources {
srcDir 'src/integration-test/resources'
}
compileClasspath += sourceSets.main.runtimeClasspath
}
}
Bản sao có thể có của [Làm cách nào để thêm nguồn mới vào Gradle?] (Http://stackoverflow.com/questions/11581419/how-do-i-add-a-new-sourceset-to- gradle) –