gpt4 book ai didi

java - 使用 Maven 命令执行特定的 JUnit 测试用例

转载 作者:行者123 更新时间:2023-12-01 10:29:03 25 4
gpt4 key购买 nike

我已经编写了一个新的 JUnit 测试用例,我想使用 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] ------------------------------------------------------------------------

最佳答案

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

official documentation

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". The test patterns prefixed with a ! will be excluded.

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

mvn -Dtest=hello_Test test

或者仔细检查您的输入,以防出现任何拼写错误(根据您的评论)。

关于java - 使用 Maven 命令执行特定的 JUnit 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35197035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com