Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@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:

Adding 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:

Cannot resolve symbol 'ParameterizedTest'

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.

like image 408
Aloso Avatar asked Jan 17 '18 18:01

Aloso


2 Answers

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).

like image 183
Hay Avatar answered Sep 28 '22 07:09

Hay


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.

like image 38
Rakesh Raut Avatar answered Sep 28 '22 07:09

Rakesh Raut