IntelliJ 2020.3 problem with JUnit5
The existing project running unit tests in IntelliJ 2020.2 works fine. Importing the project into Intelli 2020.3 fails to recognize JUnit5 tests.
The project is configured with Maven and specifically excludes JUnit 4 dependencies.
pom.xml snipped
<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
Running a unit test with IntelliJ 2020.3 fails with this error: (Right click -> Select Run)
Internal Error occurred.
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' failed to discover tests
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:111)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:85)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:92)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: org.junit.platform.commons.JUnitException: Failed to parse version of junit:junit: 4.13.1
at org.junit.vintage.engine.JUnit4VersionCheck.parseVersion(JUnit4VersionCheck.java:54)
at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:37)
at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:32)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:62)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:103)
... 7 more
Process finished with exit code 254
Project is running on MacOS BigSur with Java 15 OpenJDK
The environment does not seem to be impacting this.
When looking at the IntelliJ plugings -> JUnit -> JUnit Tests
This takes you to the JUnit4 GitHub link -> https://github.com/junit-team/junit4
The older IntelliJ also takes you to this link. So not too sure if it is part of the problem.
About information:
IntelliJ IDEA 2020.3 (Ultimate Edition)
Build #IU-203.5981.155, built on December 1, 2020
Licensed to Andre Kapp
Subscription is active until December 28, 2020
Runtime version: 11.0.9+11-b1145.21 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.16
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 12
Non-Bundled Plugins: awesome.console, com.andrey4623.rainbowcsv, com.robohorse.robopojogenerator, krasa.CpuUsageIndicator, main.kotlin.com.jimschubert.intellij.swaggercodegen, manjaro.mpb, net.seesharpsoft.intellij.plugins.csv, org.intellij.plugins.hcl, org.zalando.intellij.swagger, tech.central.ai.awstail, DBN, com.intellij.kubernetes, com.godwin.json.parser, net.hexar.json2pojo, org.sonarlint.idea, io.github.satr.idea.plugin.connector.la, nb-mind-map-idea, com.ifengxue.plugin.jpa-support, com.viartemev.requestmapper, izhangzhihao.rainbow.brackets, Pythonid, OdpsStudio, aws.toolkit
请先登录再写评论。
Hello,
Please clarify the versions of the dependencies used and also please provide the little test sample the case is reproduced for you with. Thank you
Sure - Running SpringBoot 2.4.0
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Other dependency versions:
<properties>
<java.version>15</java.version>
<model.mapper.version>2.3.8</model.mapper.version>
<maria.db.client.version>2.6.2</maria.db.client.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
<testcontainers.version>1.15.0</testcontainers.version>
</properties>
All the unit/integration tests fail with the same error.
None of the test cases want to run.
To answer on a sample.
Sample test class:
package za.co.mamamoney.ozow.controller.callbacks;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import za.co.mamamoney.ozow.services.eventhandling.CallbackThreadPoolService;
import za.co.mamamoney.ozow.services.validationservices.HashGenerator;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
@WebMvcTest(CancelledResponseController.class)
class CancelledResponseControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private CallbackThreadPoolService callbackThreadPoolService;
@MockBean
private HashGenerator hashGenerator;
private WebTestClient webTestClient;
@BeforeEach
public void setup() throws Exception{
this.webTestClient = MockMvcWebTestClient
.bindTo(mockMvc)
.filter(logRequest())
.build();
doNothing().when(callbackThreadPoolService).handleCallbackAction(any());
doNothing().when(hashGenerator).validateReceivedHash(any());
}
@Test
void shouldAcceptInputAndReturnStatus200_valid_hashcode() throws Exception {
EntityExchangeResult<byte[]> result = this.webTestClient
.get()
.uri(buildCancelledInboundString())
.exchange()
.expectStatus().is2xxSuccessful()
.expectBody().returnResult();
}
private ExchangeFilterFunction logRequest() {
return (clientRequest, next) -> {
System.out.printf("Request: %s %s %n", clientRequest.method(), clientRequest.url());
return next.exchange(clientRequest);
};
}
private String buildCancelledInboundString() {
String uri = "/api/v1/callback/cancelled?SiteCode=MAM-MAM-004&TransactionId=a95cc440-5f68-45c6-97e1-a8b98ff398fe&TransactionReference=transref&Amount=100.23&Status=Cancelled&Optional1=&Optional2=&Optional3=&Optional4=&Optional5=&CurrencyCode=ZAR&IsTest=True&StatusMessage=Test+transaction+completed&SubStatus=Unclassified&Hash=9f7a3ca44806ad958b1c76c1fe0767bd9fc39110358d04132241bf8ed20381831954679fda25c61cf81a73951536db4245af2822018d4c2f76e89ff042e0baa6";
return uri;
}
}
Below is the complete pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>za.co.mamamoney</groupId>
<artifactId>ozow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ozow</name>
<description>Ozow integration for MamaMoney</description>
<properties>
<java.version>15</java.version>
<model.mapper.version>2.3.8</model.mapper.version>
<maria.db.client.version>2.6.2</maria.db.client.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
<testcontainers.version>1.15.0</testcontainers.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${maria.db.client.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hppc</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-json-org</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>${model.mapper.version}</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>
<!-- TestContainers for the DB and MockServer tests -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-junit-jupiter</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mockserver</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<excludedGroups>IntegrationTest</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
<groups>IntegrationTest</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Unfortunately the issue is not reproduced on my side with the following dependencies and a simple test sample (provided below).
If possible can you please check if the problem is reproduced for you with my sample as well?
Please share your project sample here: https://uploads.services.jetbrains.com/
in case the issue occurs only with your data. Thank you
Please find attached the tar file of the complete project.
Upload id: 2020_12_10_UKGtfvPzKB3wkgCS (file: fresh.tar.gz)
Have a look at the RestTemplateHandlerImplTest, AWSQueueMessageListenerITTest and ContactCreateMessageHandlerTest test classes.
The test runs fine with at cmd maven test:
Thank you for taking the time to help and sort this out.
Please enable the OAuth2 dependencies to compile.
Hello,
Please clarify if the tests start running fine for you with IntelliJ IDEA 2020.3 if you comment out the exclusion part in dependencies?
Thank you
Nope - unfortunately still the same problem.
Reloaded the project after compiling with cmd maven from a terminal session. Tried different build options.
Still failing with the same error.
PS - This happening to a couple of my other projects as well.
Works fine in 2020.2 but fails in 2020.3
Hello,
Please follow the issue created for your problem at YouTrack: https://youtrack.jetbrains.com/issue/IDEA-257728
Thank you for the report.