Maven - 在模块中运行JUnit Testsuite

L.B*_*utz 4 java unit-testing junit4 maven

我有3个项目:

  • ParentProj(A + B的父母)
  • ProjA(是ParentProj的一个模块,包含源代码)
  • ProjB(是ParentProj的一个模块,包含源和测试)

构建顺序是:1.ParentProj,2.ProjA,3.ProjB(无法更改!)

我想告诉maven执行位于ProjB中的TestSuite.如果我使用此命令运行构建:mvn clean -e test -Dtest=AllServiceTests,构建将失败,因为maven无法在ProjA中找到"AllServiceTests"类,它是在ProjB之前构建的.

这个问题有什么解决方案吗?(更改构建顺序不是解决方案)

L.B*_*utz 9

我刚刚找到了解决方案:

clean install test -Dtest=myTestSuite -DfailIfNoTests=false 
Run Code Online (Sandbox Code Playgroud)

-DfailIfNoTests=false 如果ProjA不包含Test类,将强制maven继续构建.

这终于解决了我的问题.