13

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

xingbin
  • 27,410
  • 9
  • 53
  • 103
Team
  • 587
  • 2
  • 9
  • 21
  • could you show output results of junit – Afaq Ahmed Khan Oct 02 '18 at 05:16
  • @afaq I have edited and attached the screen caption of Event log into my post. – Team Oct 02 '18 at 05:19
  • Always gotta make sure.... did you build/make your changes? – shinjw Oct 02 '18 at 06:07
  • I don't understand. Can you please clarify what you mean? I'm a newbie ^^". @shinjw – Team Oct 02 '18 at 06:12
  • `Ctrl+F9`. Sometimes your latest changes does not make it to Runtime depending on how you have your IntelliJ set up. – shinjw Oct 02 '18 at 06:15
  • @shinjw i tried it, it still passed the test. – Team Oct 02 '18 at 06:20
  • 5
    When telling IntelliJ to execute a single test, it will always execute it - regardless of whether it is disabled or not. If executing the entire class, disabled tests _shouldn't_ be run, but maybe you discovered a bug for the case that the test class only contains a single test method. Try adding a second method and execute them individually as well as the class. If this turns out to be a bug, report it. – Nicolai Parlog Oct 02 '18 at 08:13
  • I tried to run it for 3 tests the result is the same, the system don't ignore a test. How can i report this bug to IntelliJ? just writing them an email? – Team Oct 03 '18 at 05:59

4 Answers4

7

@Nicolai answer is 100% correct, IntelliJ will execute test if you force it to be executed by IntelliJ.

However, if you want to enable @Disabled annotation in build management system, remember about surefire plugin (details). If it is missing, annotation will not work.

staszko032
  • 802
  • 6
  • 16
  • The OP has tried this method but it seems does not work. See his comment. https://stackoverflow.com/a/52602566/6690200 – xingbin Oct 02 '18 at 14:56
  • 1
    I'm using `org.apache.maven.plugins:maven-surefire-plugin:2.22.0` and IntelliJ IDEA 2019.2.2 (Ultimate Edition) Build #IU-192.6603.28, built on September 6, 2019 and `@Disabled` is not working for classes which have a single `@Test` method that also have that method `@Disabled` – Tony Falabella Oct 16 '19 at 20:34
2

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

Tony Falabella
  • 335
  • 1
  • 6
  • 17
0

@Tony Falabella

In the Jira I replied to you with a hint. Please use the latest snapshot version 3.0.0-SNAPSHOT and let me know about this issue. This snapshot version can be found on Apache Nexus repository. Please provide us with your feedback asap during the development of the plugin and try to use snapshot version because this avoids new issues:

<pluginRepository>
  <id>surefire-snapshot</id>
  <name>surefire-snapshot</name>
  <url>https://repository.apache.org/content/repositories/snapshots/</url>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
 </pluginRepository>
...
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.0.0-SNAPSHOT</version>
    </plugin>
  </plugins>
</build>

In Jira I found that you use

<artifactId>junit-platform-launcher</artifactId>

Please do not use it. It is not related to you. It is related to usages by Surefire/Failsafe and IDEs only.

tibor17
  • 1,043
  • 6
  • 9
0

With JUnit 5.8.2 and maven surefire 2.22.2 I see this issue also

NB. only test methods whose name starts "test..." seem to be affected for me. If your test methods have a different name I can't reproduce the issue. Hence workaround is to rename the test method to not start "test..."

Greg Allen
  • 337
  • 2
  • 8