【发布时间】:2019-07-11 19:33:08
【问题描述】:
我有 Groovy 课程
package com.steinko.groovy;
class Student {
String name;
int ID;
Student(name,ID){
this.name = name;
this.ID = ID;
}
String Display() {
return name +ID;
}
}
还有一个 Junit 5 测试
package com.steinko.groovy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class StudenTest {
@Test
void testDisplay() {
def stud = new Student('Joe', 1)
def expected = 'Joe1'
assertEquals(stud.Display(), expected)
}
}
我有一个 Gradle build.gradle
apply plugin: 'groovy'
test {
useJUnitPlatform()
}
repositories {
jcenter()
}
dependencies {
implementation localGroovy()
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.0")
}
当我执行 gradle build 时,我收到以下消息
com.steinko.groovy.StudenTest > testDisplay() FAILED
groovy.lang.MissingMethodException: No signature of method: >com.steinko.groovy.StudenTest.assertEquals() is applicable for >argument types: (String, String) values: [Joe1, Joe1]
at >org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:72)
at >org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:80)
at >org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
at >org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)
at >org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:176)
at >com.steinko.groovy.StudenTest.testDisplay(StudentTest.groovy:14)
测试结果
groovy.lang.MissingMethodException: No signature of method: com.steinko.groovy.StudenTest.assertEquals() is applicable for argument types: (String, String) values: [Joe1, Joe1]
at >org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:72)
at >org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:80)
at >org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
at >org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)
at >org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:176)
at com.steinko.groovy.StudenTest.testDisplay(StudentTest.groovy:14)
如何修复错误?
【问题讨论】:
-
粘贴
./gradlew -version的输出。我无法使用 Gradle 5.5 和 4.6+ 重现您的问题。如果您的测试缺少Assertions.assertEquals的静态导入,则该错误是有意义的,但它就在那里。 -
------------------------------------------ ------------------ Gradle 5.5 ------------------ ------------------------------ 构建时间:2019-06-28 17:36:05 UTC 修订:83820928f3ada1a3a1dbd9a6c0d47eb3f199378f Kotlin:1.3 .31 Groovy:2.5.4 Ant:2019 年 3 月 12 日编译的 Apache Ant(TM) 版本 1.9.14 JVM:12.0.1(Oracle Corporation 12.0.1+12) 操作系统:Mac OS X 10.14.5 x86_64