[ 
https://issues.apache.org/jira/browse/NETBEANS-3733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17109375#comment-17109375
 ] 

Svatopluk Dedic commented on NETBEANS-3733:
-------------------------------------------

I did reproduce using the steps in the initial comment. I'm not sure if it 
qualifies to {{Critical}} as a workaround exists:
 * you seem to use *JUnit 5*, the added dependency is *JUnit 4*, which is 
probably NOT what you'd want. Remove the added dependency and add Junit's 5 
package to shut NetBeans up:

{code:java}
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.6.0</version>
            <scope>test</scope>
        </dependency>{code}

 * Despite [Maven 
Documentation|[https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html]]
 says that the syntax {{ClassName#method}} works from *surefire 2.7.3*, I was 
able to get it work only for *surefire 2.22.0* and above. I have Maven *3.6.0* 
installed separately and on my installation, *surefire 2.12.4* is used by 
default. Check (run with -X, show debug output) if it is your case. Update your 
{{pom.xml}} with

{code:java}
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

{code}
to force *2.22.0* version

Of course NB JUnit support *should* recognize JUnit Jupiter artifacts and "do 
the right thing". 

> Cannot test single method with Maven and Junit 5
> ------------------------------------------------
>
>                 Key: NETBEANS-3733
>                 URL: https://issues.apache.org/jira/browse/NETBEANS-3733
>             Project: NetBeans
>          Issue Type: Bug
>          Components: java - JUnit, projects - Maven
>    Affects Versions: 11.1, 11.2, 11.3
>            Reporter: Bernard
>            Priority: Critical
>
> 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?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to