我知道您可以使用以下方法在某个类中运行所有测试:
mvn test -Dtest=classname
但我想运行一个单独的方法和-Dtest=classname。Methodname似乎不起作用。
我知道您可以使用以下方法在某个类中运行所有测试:
mvn test -Dtest=classname
但我想运行一个单独的方法和-Dtest=classname。Methodname似乎不起作用。
当前回答
首先,你需要清理你的专业项目
mvn戒毒
然后您可以使用运行特定的文件和函数
mvn test -Dtest=testClassName#testCaseName
其他回答
您可以运行单个测试类,但不能运行测试类中的单个方法。使用类的简单名称,而不是类的完全限定名称。如果你在"org。sontype。test "中有一个测试。MyTest”,这是你唯一想要运行的测试,你的命令行看起来是这样的:
mvn test -Dtest=MyTest
我用我的TestNG(对不起,JUnit不支持这个)测试用例所做的是,我可以为我想要运行的测试分配一个组
@Test(groups="broken")
然后简单地运行'mvn -Dgroups=broken'。
新版本的JUnit包含Categories运行器: http://kentbeck.github.com/junit/doc/ReleaseNotes4.8.html
但是JUnit的发布过程不是基于maven的,因此maven用户必须手动将其放入他们的存储库中。
tobrien提到的test参数允许您在方法名称前使用#来指定方法。这应该适用于JUnit和TestNG。我从来没有尝试过,只是在Surefire插件页面上阅读:
Specify this parameter to run individual tests by file name, overriding the includes/excludes parameters. Each pattern you specify here will be used to create an include pattern formatted like **/${test}.java, so you can just type "-Dtest=MyTest" to run a single test called "foo/MyTest.java". This parameter overrides the includes/excludes parameters, and the TestNG suiteXmlFiles parameter. since 2.7.3 You can execute a limited number of method in the test with adding #myMethod or #my*ethod. Si type "-Dtest=MyTest#myMethod" supported for junit 4.x and testNg
您可以使用以下语法运行特定的测试类和方法:
完整包:mvn test -Dtest="com.oracle.tests.**" mvn test -Dtest=CLASS_NAME1 mvn test -Dtest=CLASS_NAME1#METHOD_NAME1 来自多个类的多个方法:mvn test -Dtest=CLASS_NAME1#METHOD_NAME1,CLASS_NAME2#METHOD_NAME2