You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Andreas Pabst (Jira)" <ji...@apache.org> on 2022/10/10 22:21:00 UTC

[jira] [Commented] (SUREFIRE-2115) Unable to execute specific inner class test in Surefire

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

Andreas Pabst commented on SUREFIRE-2115:
-----------------------------------------

This is not a bug.

If you are running the tests on Linux, you need to escape the dollar symbol on the command line, otherwise {{$TestClass2}} will be replaced with the content of the environment variable {{TestClass2}} - or an empty string if it doesn't exist. Essentially what you're writing is therefore equivalent to {{mvn clean test -Dtest=NestClassContainer}}, so it's not surprising that all tests are executed.

This should work:

{noformat}
mvn clean test -Dtest=NestClassContainer\$TestClass2 
{noformat}

> Unable to execute specific inner class test in Surefire
> -------------------------------------------------------
>
>                 Key: SUREFIRE-2115
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-2115
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Surefire Plugin, TestNG support
>            Reporter: Baubak Gandomi
>            Priority: Major
>
> Hi I have a nested class hierarchy which is as follows:
> {code:java}
> public class NestClassContainer {
>     @Test
>     public static class TestClass1 {
>         public void testC1_m1() {
>             System.out.println("Should not execute");
>         }
>     }
>     @Test
>     public static class TestClass2 {
>         public void testC2_m1() {
>             System.out.println("Should execute");
>         }
>     }
> }{code}
> I want to use Surefire to only execute NestClassContainer$TestClass2, This works just fine in TestNG exeution, but I cannot get it to work in Surefire.
> When I try to execute one of the nested classes TestClass2 , it executes all the tests in the top class. (Tested versions 2.22.1 & 3.0.0-M7)
> Here is my commandline:
> {code:java}
> mvn clean test -Dtest=NestClassContainer$TestClass2 {code}
> Expected outcome:
> We execute only testC2_m1
> Actual outcome:
> Both testC1_m1 & testC2_m1 are executed.
> I have even tries setting the annotations on the test methods instead, but the result is the same.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)