Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit 5 Disabled is ignored?

I'm using JUnit 5 with IntelliJ IDEA Community Edition version 2018.

My code is simple:

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

class CalculatorTest {

    @Disabled
    @Test
    void addTwoZeroNumerators(){
    int[] resultExpected = {0,0};
    assertArrayEquals(resultExpected, Calculator.calculate(0,0,0,1));
}

I use @Disabled. But when I run the test, the Event log still report 1 test passed. Can someone tell me what's wrong with this? I want the system to Ignore this test.

Here is the caption of the log section:

enter image description here

like image 411
Team Avatar asked Oct 02 '18 05:10

Team


People also ask

How do you ignore a JUnit 5 test?

JUnit 5 – @Disabled Annotation You may disable or skip execution for a test method or a group of tests by applying the annotation at the Test level. Or all the tests could be skipped by applying @Disabled annotation at the class level instead of applying it to the test method level.

Why is JUnit test ignored?

The @Ignore annotation helps in this scenario. A test method annotated with @Ignore will not be executed. If a test class is annotated with @Ignore, then none of its test methods will be executed.

How do I disable JUnit?

A second option would be to disable tests temporarily using the JUnit @Ignore annotation. We can add it at the class level to disable all tests in a class: @Ignore("Class not ready for tests") public class IgnoreClassUnitTest { @Test public void whenDoTest_thenAssert() { // ... } }

How do I disable JUnit test cases?

1) Ignoring a single test method in JUnit, just annotate method with @Ignore annotation. 2) Ignoring a single test method but with proper reason, annotate method with @Ignore annotation but also give String argument as reason. 3) Ignoring all methods of a test class in JUnit, just use @Ignore annotation at class level.


1 Answers

I think this may be a bug with Maven SureFire Plugin where if you have a class with a single @Test and it's also @Disabled it still tries to run it. I've tried on maven-surefire-plugin:2.22.0, 2.22.2, and 3.0.0-M3 and all seem to have the issue.

Ticket opened with Apache Maven team:

https://issues.apache.org/jira/browse/SUREFIRE-1700?filter=-2

Tickets opened with JetBrains:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006399720-IDEA-2019-2-2-Ultimate-Edition-ignores-Disabled-for-JUnit5-tests-having-a-single-Test-method

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006399760-IDEA-2019-2-2-Ultimate-Edition-requires-junit-vintage-engine-for-Maven-package-using-only-JUnit5

like image 111
Tony Falabella Avatar answered Oct 05 '22 23:10

Tony Falabella