我正在使用 Gradle (Milestone 8a) 使用 IBM J9 JVM 在我的项目上运行 JUnit 测试,根据“使用 JMockit 运行测试”要求我将参数传递-javaagent:jmockit.jar
给 JVM。但是,JMockit 没有注入模拟参数,这导致我的测试失败,并显示“方法(foo)应该没有参数)”。测试在 HotSpot JVM 上的 Eclipse 中运行良好。
我已扩展test
任务以查找 JAR 并将参数添加到jvmArgs
如下所示:
test {
doFirst {
// Don't do this until the task is actually being executed, because
// as soon as we call testCompile.find the configuration is resolved and
// can't be modified anymore.
jMockit = project.configurations.testCompile.find {
it.name.startsWith("jmockit-")
}
jvmArgs "-javaagent:${jMockit}"
}
}
我还在testCompile
配置中添加了 JMockit 和 JUnit,确保首先使用 JMockit,并通过运行验证这一点gradle dependencies
:
dependencies {
testCompile 'com.googlecode.jmockit:jmockit:0.999.13'
testCompile 'junit:junit:4.10'
}
的输出gradle check --debug
确认-javaagent
正在使用该参数:
12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] creating process builder for Gradle Worker 1
12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] in directory /home/bbobby/webapp
12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#0 = -javaagent:/home/bbobby/.gradle/caches/artifacts-8/filestore/com.googlecode.jmockit/jmockit/0.999.13/jar/a6
ba457e09361f37e386edea176c5ce4fa9ee110/jmockit-0.999.13.jar
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#1 = -ea
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#2 = -cp
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#3 = /home/bbobby/.gradle/caches/1.0-milestone-8a/workerMain/classes
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#4 = org.gradle.process.internal.launcher.GradleWorkerMain
12:44:14.816 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Started Gradle Worker 1.
我很确定我已经做了我应该做的一切。为什么我的测试无法运行?