使用Maven Command

时间:2016-02-04 09:22:12

标签: java windows maven junit

我编写了一个新的JUnit Test案例,我想用maven命令编译。我试图从pom.xml的位置执行此命令,这是命令 -

mvn -Dtest=src\test\java\absolute\path\of\JUnit\test\hello_Test.java test

这是我得到的输出(说没有要运行的测试) -

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building my-maven-component
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 81 resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 85 resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\projects\absolute\path\of\maven\component\my-maven-component\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Thu Feb 04 13:53:08 IST 2016
[INFO] Final Memory: 26M/64M
[INFO] ------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:1)

您不需要完整路径来运行特定测试,test选项的值实际上是一种模式。

official documentation

开始
  

指定此参数以按文件名运行单个测试,覆盖includes / excludes参数。您在此处指定的每个模式将用于创建格式为** / $ {test} .java的包含模式,因此您只需键入" -Dtest = MyTest"运行一个名为" foo / MyTest.java"的测试。测试图案前缀为!将被排除在外。

所以你甚至可以简单地运行:

mvn -Dtest=hello_Test test

或者在发生任何拼写错误的情况下仔细检查您的输入(根据您的评论)。