使用Maven和Jnunit从命令行运行单个方法

时间:2017-08-29 10:21:19

标签: maven junit maven-surefire-plugin

我正在尝试使用maven或Junit从命令行运行单个测试方法的apporaf。我的项目是使用Maven在Junit Framework中构建的。

我有并行执行以并行运行方法。当我尝试从命令行运行它时,它仍然并行运行所有testmenthds。

mvn -Dtest=<Classname>#<testmethodname> test

有人会帮忙,如何从命令行运行单一的testmethod或sepcific测试方法。

版本: junit - 4.9 maven-compiler-plugin - 2.5.1 maven-surefire-plugin - 2.8

这是参考的日志

    [INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <ProjectName> 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @  ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @  ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory 
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @  ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.8:test (default-test) @  ---
[INFO] Surefire report directory: C:\Automation\......\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Concurrency config is parallel='methods', perCoreThreadCount=false, threadCount=6, useUnlimitedThreads=false
Destroying 1 processes
Destroying process..
Destroyed 1 processes
Terminate batch job (Y/N)?

2 个答案:

答案 0 :(得分:1)

用于排除单个测试的surefire参数为test而非Test,因此您应调用以下Maven命令:

mvn -Dtest=<ClassName>#<TestMethodName> test

例如,给定......

  • 带有测试方法的测试FooTestfoo()
  • 带有测试方法的测试BarTestbar()

...你可以调用以下内容:

  • 运行FooTest.foo()

    mvn -Dtest=FooTest#foo test
    
  • 运行FooTest.foo()和BarTest.bar()

    mvn -Dtest=FooTest#foo,FooTest#bar test
    

答案 1 :(得分:1)

拼写错误发现好友,正确的是 -Dtest 而不是-DTest

SELECT DISTINCT T1.ID, T1.PNo, T1.MM, T1.CP
FROM            Table1 T1 INNER JOIN Table1 T2 ON T1.PNo = T2.PNo
WHERE           T1.MM <> T2.MM
ORDER BY        T1.ID  

此外,由于您已经并行运行多个测试,您还可以使用下面提到的模式来执行类似测试方法。

示例:

mvn -Dtest=<Classname>#<testmethodname> test 

享受......;)