Как мне проверить Groovy от Junit5? - PullRequest
0 голосов
/ 11 июля 2019

У меня 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, я получаю следующее сообщение

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)

Как исправить ошибку?

1 Ответ

0 голосов
/ 12 июля 2019

Использование методов из org.junit.jupiter.api.Assertions редко требуется в Groovy, поскольку встроенная в Groovy команда assert очень мощная.

Просто попробуйте

assert stud.Display() == expected

и посмотрите, насколько хороши отчеты об ошибках.

...