0

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

如何修复错误?

4

1 回答 1

0

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

试试看嘛

assert stud.Display() == expected

看看故障报告有多好。

于 2019-07-12T18:56:38.413 回答