java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute - PullRequest
0 голосов
/ 14 мая 2018

Я пытаюсь запустить следующий пример модульного теста

class ExampleUnitTest {

    @Test
    fun addition_is_Correct() {
        assertEquals(4, (2 + 2).toLong())
    }

}

но я получаю следующее исключение

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

, хотя я обновил весь файл build.gradle зависимостей Junit, как показано ниже

testImplementation 'junit:junit:4.12'
testImplementation 'org.jetbrains.spek:spek-api:1.1.5'
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
testImplementation 'org.junit.platform:junit-platform-launcher:1.0.0'
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:4.12.3'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.0.0'

есть ли решение для этого?

1 Ответ

0 голосов
/ 19 июня 2018

TL; DR понизить ваши зависимости в pom.xml в соответствии с версиями, изначально поставляемыми с IDEA, найденными в IDEA_INSTALLATION_HOME/plugins/junit/lib


Более длинная версия:

Предположим, вы используете версию Intellij IDEA старше 2017 года;тогда у вас есть эти варианты, которые были даны в качестве официального ответа на другой вопрос SO: https://intellij -support.jetbrains.com / hc / en-us / community / posts / 115000791190-Intellij-do-not-run-Junit5-tests

Вставьте его сюда, чтобы сделать его более заметным:

Среда IDE зависит от компиляции старого jar-файла запуска junit 5 и не совместима с текущим выпускомверсия.Таким образом, у вас есть возможность обновить IDE, чтобы она была совместима с используемой вами версией junit или чтобы понизить версию junit (проверьте, какая версия была включена в IDEA_INSTALLATION_HOME / plugins / junit / lib).У 2017.1 была только экспериментальная поддержка для junit 5, так как junit 5 еще не была выпущена.Приносим извинения за неудобства.

Итак, перейдите в папку IDEA_INSTALLATION_HOME/plugins/junit/lib и проверьте версии в именах найденных там файлов jar.Должно быть что-то вроде этого:

user@comp:IDEA_INSTALLATION_HOME/plugins/junit/lib]$ ls
idea-junit.jar                        junit-platform-runner-1.0.0-M4.jar
junit5-rt.jar                         junit-platform-suite-api-1.0.0-M4.jar 
junit-jupiter-api-5.0.0-M4.jar        junit-rt.jar
junit-jupiter-engine-5.0.0-M4.jar     junit-vintage-engine-4.12.0-M4.jar
junit-platform-commons-1.0.0-M4.jar   opentest4j-1.0.0-M2.jar
junit-platform-engine-1.0.0-M4.jar    resources_en.jar
junit-platform-launcher-1.0.0-M4.jar

Теперь используйте суффикс версии junit- имени файла в настройках pom.xml properties вашего модуля:

<project>
...
    <properties>
        <junit.jupiter.version>5.0.0-M4</junit.jupiter.version>
        <junit.platform.version>1.0.0-M4</junit.platform.version>
        <junit.vintage.version>4.12.0-M4</junit.vintage.version>
        ...
    </properties>
...
</project>

Я могу подтвердить, что после измененияв более старых версиях я мог запускать тестовые классы, которые использовали пакет org.junit.jupiter.До этого я постоянно получал NoSuchMethodError при попытке запустить Тесты.

...