Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-3733

Cannot test single method with Maven and Junit 5

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 11.1, 11.2, 11.3
    • 12.0
    • None

    Description

      All defaults, hello world application as simple as possible.

      How to reproduce:

      Menu|File|New Project|Java with Maven|Java Application|Finish
      Projects|New|java Class|NewClass|Finish

      Add two methods:

      public void hello1()

      { System.out.println("Hello 1"); }

      public void hello2()

      { System.out.println("Hello 2"); }

      [Ctrl+Shift+U] Create / Update Tests|JUnit|OK

      generates test as expected, adds dependencies to POM as expected:

      <dependencies>
      <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.3.1</version>
      <scope>test</scope>
      </dependency>
      <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <version>5.3.1</version>
      <scope>test</scope>
      </dependency>
      <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.3.1</version>
      <scope>test</scope>
      </dependency>
      </dependencies>

      In generated class NewClassTest now I want to test the single method "testHello2()"

      So I put cursor on it and right click, "Run Focused Test Method".

      I get a dialog:

      "Feature requires update of POM"

      "Executing single test method requires Surefire 2.8+ and JUnit in version 4.8 and bigger.
      Update your pom.xml?"

      I click "Yes"

      In pom.xml, another dependecy is added:

      <dependency>
      <artifactId>junit</artifactId>
      <groupId>junit</groupId>
      <version>4.11</version>
      </dependency>

      Si I try again. Put cursor on the method and right click, "Run Focused Test Method".

      I get a message

      "No tests executed for mavenproject1"

      This means that I cannot use the default way of NetBeans to quickly create a class and test it.

      This reproduces with all only defaults selected such as Java Maven project, as simple as it can get. This has worked for about 10 years until it was broken with JUnit 5.

      How can we select JUnit 4 until this is mature?

      Attachments

        Activity

          People

            sdedic Svatopluk Dedic
            bht Bernard
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 40m
                1h 40m