The option "Tag (JUnit 5)" does not show up in IntelliJ 2018.3

Viewed 698

I am working with JUnit 5.1.0 in a Maven project. I have IntelliJ IDEA 2018.3.2 (Community Edition). I would like to use the @Tag annotation to describe my tests and be able to filter by those.

The point is that in edit configurations | Configuration | Test Kind there is no "Tag (JUnit 5)" option like I have seen in many examples. Only the option "Tags" is provided.

When I use the option mentioned, I set the field Tag expression to "slow" (without the quotes) (I have one test already tagged like @Tag("slow")).

The point is that no test is found (the test is marked with @Test).

@Test
@Tag("slow")
public void testNotBlank() {
  // Given
  String excectedText = "";
  // When
  String text = Checks.notBlank(excectedText, "error");
  // Then
  assertEquals("", Checks.notBlank(text, "error"));
}

The pom dependency

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-engine</artifactId>
  <version>5.1.0</version>
  <scope>test</scope>
</dependency>

First of all, I expected to have the option "Tags (JUnit 5)" and I don't. Then, I expected that selecting "Tags" and giving the expression "slow", the test testNotBlank would be executed.

3 Answers

You can execute tagged tests using the following Test Configuration:

enter image description here

This can be created using the following steps:

  1. Run/Debug configurations > Add new configuration > Junit
  2. Select test kind Tags and varied configurations as to how you want to execute. e.g. I am executing the test tagged with "fast" N times.

Where the test class includes:

public class TaggedTests {

    @Test
    @Tag(value = "slow")
    public void sample() {
        System.out.println("slow-test");
    }


    @Test
    @Tag(value = "fast")
    public void fastSample() {
        System.out.println("fast-test");
    }
}

and execution outputs:

fast-test 
fast-test... 10 times

The reason why it is not working is because I was using the @Test annotation from JUnit 4 instead of using the one from JUnit 5. Because of that, filtering wasn't working even if JUnit Vintage was imported in the pom.

1)Configuration in Intellij Junit Runner

Configuration in Intellij Junit Runner

Please choose the Tags in the highlighted select box and add your tag to test the tagged test methods alone

2)Configuration using maven pom.xml

enter image description here

Add the above configuration at the level and your desire tags inside groups tag separated by a comma as shown in the picture with two tags Add and Multiply.

Related