'@ParameterizedTest can't be resolved in IntelliJ IDEA 2017.3
I'm new to JUnit testing and I would like to create a parameterized test in IntelliJ IDEA 2017.3.3. So I added JUnit 5:
Then IntelliJ downloaded org.junit.jupiter:junit-jupiter-api:5.0.0. Now, @Test is working, but @ParameterizedTest is not. It says "Cannot resolve symbol 'ParameterizedTest'". It's the same with @ValueSource:
Code:
import org.junit.jupiter.api.*;
class SSTest {
@ParameterizedTest
@ValueSource(ints = {1, 2, 3})
void testSlowSort(int arg) {
}
@Test
void testSort() {
}
}
PS: Also the package org.junit.jupiter.params is missing. Otherwise, IntelliJ would import it automatically.
I hope anyone can help me how to fix this. I am not using Maven, Gradle, etc, just Java.
Solution 1:[1]
In article 2.1.2 of JUnit docs, it is mentioned that junit-jupiter-params is a separate artifact containing support for parameterized tests.
In article 3.14, it is explained that the parameterized tests support is currently an experimental feature.
Therefore you need to add the junit-jupiter-params artifact to your dependencies (i.e. Maven or Gradle).
Solution 2:[2]
use below import statement [Intellisense should bring those imports automatically]
import org.junit.jupiter.params.ParameterizedTest
Add following dependencies to your build.gradle.kts [for gradle builds]
testImplementation("org.junit.jupiter:junit-jupiter-params:5.6.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-params:5.6.2")
Build project and @ParameterizedTest annotation should be available. If not, then restart IntelliJ and libraries should be loaded.
Solution 3:[3]
Please use these Junit5 dependencies for your tests (including @Parameterized ones)
val junitVersion = "5.1.0"
// JUnit5
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-params:$junitVersion")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hay |
| Solution 2 | srk |
| Solution 3 | AlexPes |


