gpt4 book ai didi

gradle - 如何测试Junit5的Groovy?

转载 作者:行者123 更新时间:2023-12-03 05:34:55 25 4
gpt4 key购买 nike

我有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)

如何解决错误?

最佳答案

在Groovy中,很少需要使用org.junit.jupiter.api.Assertions中的方法,因为Groovy的内置assert命令非常强大。

你试一试

assert stud.Display() == expected

并查看故障报告的质量。

关于gradle - 如何测试Junit5的Groovy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56996161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com