Missing org.junit.jupiter.params from JUnit5

Viewed 17464

I am trying to add parameterized tests into my Java program. I found the examples for JUnit 5, which I do have included.

https://blog.codefx.org/libraries/junit-5-parameterized-tests/

The issue is I cannot add @ParameterizedTest because the namespace is missing. Idk why or how.

The documentation page clearly states it is in org.junit.jupiter.params, but I do not have that.

To give you an idea of my code:

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.jupiter.api.Assertions.*;

class SubsetPrinterTest
{
    // https://blog.codefx.org/libraries/junit-5-parameterized-tests/

    static Collection<Object[]> makeSetData()
    {
        return Arrays.asList(new Object[][]
        {
                {1, new char[]{'1'}},
                {2, new char[]{'1', '2'}},
                {3, new char[]{'1', '2', '3'}},
                {4, new char[]{'1', '2', '3', '4'}},
                {5, new char[]{'1', '2', '3', '4', '5'}}
        });
    }

    // This should be a parameterized test using the makeSetData.
    @Test
    void makeSet()
    {
        // Arrange
        SubsetPrinter subsetPrinter = new SubsetPrinter();

        // Act
        char[] set = SubsetPrinter.MakeSet(5);

        // Assert
        assertArrayEquals(set, new char[]{'1', '2', '3', '4', '5'});
        assertEquals(set.length, 5);
    }
}
3 Answers

Add the following dependency in pom.xml. jupiter API [Junit 5] approaches modules as plugins, each of on has to be deliberately added,

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-params</artifactId>
  <version>${junit.version}</version>
  <scope>test</scope>
</dependency>

More on: https://mvnrepository.com/artifact/org.junit.jupiter

Related