我试图将Gradle(1.4)添加到具有多个测试套件的现有项目中。位于中的标准单元测试已src/test/java
成功运行,但是我无法设置任务以运行位于中的JUnit测试src/integration- test/java
。
当我运行时,我在gradle intTest
遇到cannot find symbol
类错误src/main
。这使我相信依赖关系设置不正确。如何设置intTest
以便它将运行我的JUnit集成测试?
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
}
详细信息: Gradle 1.4
解决方案:
我尚未为集成测试源集设置编译类路径(请参见下文)。在我的代码中,我将编译类路径设置为,sourceSets.test.runtimeClasspath
以便没有“
integrationCompile”的重复依赖项。
sourceSets {
integrationTest {
java {
srcDir 'src/integration-test/java'
}
resources {
srcDir 'src/integration-test/resources'
}
compileClasspath += sourceSets.main.runtimeClasspath
}
}
“集成” sourceSet尚未配置其编译和运行时类路径。这就是为什么它无法从您的主要源集中找到类的原因。您可以通过以下方式配置编译和运行时类路径:
sourceSets {
integTest {
java.srcDir file('src/integration-test/java')
resources.srcDir file('src/integration-test/resources')
compileClasspath = sourceSets.main.output + configurations.integTest
runtimeClasspath = output + compileClasspath
}
}
我正在尝试将Gradle(1.4)添加到一个现有的项目中,该项目有多个测试套件。位于中的标准单元测试成功运行,但我在设置任务以运行位于中的JUnit测试时遇到了麻烦。 当我运行时,对于中的类,我遇到了几个错误。这使我认为依赖项设置不正确。如何设置以便它运行我的JUnit集成测试? Build.Gradle 细节:1.4级 解决方案:我没有为集成测试源集设置编译类路径(参见下面)。在我的I代码中,我
我使用文件路径解析 Spark 数据帧,但现在我想将路径与时间一起作为单独的列添加到生成的数据帧中。下面是一个当前的解决方案(pathToDF 是一个帮助器方法): 我正在尝试做这样的事情,但我不确定如何使用Column添加时间列: 实现它的更好方法是什么? 输入自由度: 当前结果: 预期结果:
需要一些非常具体的包装器和例程。
我想向Kotlin项目添加一个额外的“源代码集”,该项目将包含集成测试。我看到过一些帖子,其中谈到为香草Java项目或Kotlin做这件事,但使用Groovy而不是Kotlin Gradle DSL。 总之,使用静态编程语言Gradle DSL: 如何添加可以包含Kotlin代码、Java代码的附加“源代码集” 我希望目录结构看起来像: 相关的: > https://ryanharrison.co
问题内容: 索引文件如下: 我想要的是按平台计数和输出统计信息。为了进行计数,我可以将术语聚合作为字段进行计数: 这样,我就可以像预期那样将统计数据作为多个存储桶接收到。 现在,我还能以某种方式添加到这些存储桶中吗(以及用于统计的漂亮输出)?我附带的最好的看起来像: 实际上,它可以工作,并且在每个存储桶中返回非常复杂的结构: 当然,可以从此结构中提取平台的名称和网址(例如),但是是否有更干净,更简
问题内容: 我想序列化一个模型,但想包含一个附加字段,该字段要求在要序列化的模型实例上进行一些数据库查找: 什么是正确的方法?我看到你可以将额外的“上下文”传递给序列化程序,是在上下文字典中传递附加字段的正确答案吗?使用这种方法,获取我需要的字段的逻辑不会与序列化程序定义完全独立,这是理想的,因为每个序列化的实例都需要。在DRF序列化器文档的其他地方,它表示 “额外字段可以对应于模型上的任何属性或