我正在使用Gradle(Milestone 8a)在我的项目上使用IBM J9 JVM运行JUnit测试,根据“Running tests with JMockit”要求我将参数-javaagent:jmockit.jar
传递给JVM。但是,JMockit没有注入模拟参数,导致我的测试失败,“Method(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}"
}
}
我还将JMockit和JUnit添加到testCompile
配置中,确保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.
我很确定我已经做了我应该做的一切。为什么我的测试无法运行?
答案 0 :(得分:3)
这是http://issues.gradle.org/browse/GRADLE-2189,已经针对即将到来的1.0-rc-1进行了修复。您今天可以试用release candidate。