maven :: run only single test in multi-module project

后端 未结 3 946
忘掉有多难
忘掉有多难 2021-01-30 03:39

Is there any way to provide some command-line argument in order to skip all tests but one on some module? So I will not need to change pom.xml every time I will need to run anot

3条回答
  •  一向
    一向 (楼主)
    2021-01-30 04:40

    Other answers I see are not fully complete, for projects that depend on other sub-modules to be built. One option is to run mvn install to have the required jars to be installed into ~/.m2/..., but that option is not very "clean".

    Following command will build the sub-modules, and run only the test class that is specified. This is to be run at parent module level. Also, no need to specify sub-module name.

    mvn test -DfailIfNoTests=false -Dtest={test_class_name} -am
    

    As an aside, this can also be mvn clean test -Dfa...... I have a habit of always running clean when running tests.

    References..
    -am will make all the other sub-modules.
    -DfailIfNoTests=false does not fail the entire process since we are not intending to run tests in other modules.
    -pl option is not needed since -am is already building everything

提交回复
热议问题