This question has been asked before (e.g. here), but my observation was not the same as those previously reported.
I noticed that to get JUnit 5 to work, I must include the overall JUnit 5 artifact
testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
If I, instead, included the individual artifacts, then the JUnit test would not be picked up
testImplementation('org.junit.platform:junit-platform-runner:1.3.1')
testImplementation('org.junit.platform:junit-platform-launcher:1.0.0')
testImplementation('org.junit.jupiter:junit-jupiter-engine:5.5.1')
testImplementation('org.junit.jupiter:junit-jupiter-api:5.5.1')
testImplementation('org.junit.jupiter:junit-jupiter-params:5.5.1')
testImplementation('org.junit.vintage:junit-vintage-engine:5.5.1')
Has anyone seen something similar before?
(I also tried this with a non-Spring-Boot project -- in that case it was okay to include the individual artifacts. This was causing a lot of confusion.)
Here I am showing the result with gradle, but I have had similar result with maven too.
I am using Gradle 5.4.1
, Spring Boot 2.1.7.RELEASE
, and JUnit 5.5.1
I am including the full build.gradle
and the test class below
build.gradle
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
// testImplementation('org.junit.platform:junit-platform-runner:1.3.1')
// testImplementation('org.junit.platform:junit-platform-launcher:1.0.0')
// testImplementation('org.junit.jupiter:junit-jupiter-engine:5.5.1')
// testImplementation('org.junit.jupiter:junit-jupiter-api:5.5.1')
// testImplementation('org.junit.jupiter:junit-jupiter-params:5.5.1')
// testImplementation('org.junit.vintage:junit-vintage-engine:5.5.1')
}
test {
useJUnitPlatform()
}
DemoApplicationTest.java
package com.example.demo;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DemoApplicationTests {
@Test
public void failMe() {
Assertions.assertTrue(Boolean.FALSE);
}
}
Note that in this case I was expecting an exception be thrown in the test method failMe()
-- so as to prove that the test method had been picked up by the runner and was not silently ignored.