Юнит 5 и Мокито - PullRequest
       12

Юнит 5 и Мокито

0 голосов
/ 16 апреля 2020

С Java 14 и JUnit 5, если я добавляю mockito-junit-jupiter в мою сборку, выдается ошибка при попытке запустить mvn test даже без использования mockito в каких-либо тестах. Без мокито-юнит-юпитера все в порядке. Все зависимости являются последними версиями, кроме Maven.

Выдается ошибка

    # Created at 2020-04-15T16:34:33.816
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
    at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:189)
...
Caused by: java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ReflectiveInvocationContext
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.<clinit>(ClassBasedTestDescriptor.java:81)


    <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine -->
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-commons -->
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-commons</artifactId>
    <version>1.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-suite-api -->
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-suite-api</artifactId>
    <version>1.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner -->
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-runner</artifactId>
    <version>1.6.2</version>
</dependency>

    <!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-junit-jupiter</artifactId>
    <version>3.3.3</version>
</dependency>

1 Ответ

0 голосов
/ 17 апреля 2020

Порядок зависимостей Maven представляется важным при смешивании JUnit 5 и Mockito. Зависимости Mockito ДОЛЖНЫ следовать за аналогичными для JUnit 5. Может быть, это только для mockito-junit-jupiter, но я пытаюсь сгруппировать их вместе.

...