在Maven运行单元测试之前需要检查环境

时间:2019-05-10 16:28:13

标签: maven

首先-我是maven的新手,我几乎无法拼写。

我们已经将测试问题归结为一个丢失的文件,该文件应该是开发人员环境的一部分。我们希望将来在运行单元测试之前通过验证此文件(可能还有其他文件)来避免这种情况。我们不希望文件成为依赖项,因为构建文件并不需要它,而只是单元测试。

最佳做法是什么?我正在寻找的东西的描述很差。...

   <somephase>
      <required>
         <files>
            <file>/some/path/to/some/needed/file</file>
         </files>
      </required>
   </somephase>

我的搜索没有任何结果。预先感谢。

更新-找到了这个https://maven.apache.org/enforcer/enforcer-rules/requireFilesExist.html,但是我不确定何时真正执行。我宁愿只在要运行单元测试时执行检查。

1 个答案:

答案 0 :(得分:0)

发现了这个:https://maven.apache.org/enforcer/enforcer-rules/requireFilesExist.html

我正在使用什么...请注意如果跳过单元测试,则跳过插件的标签。

        <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-enforcer-plugin</artifactId>
           <version>3.0.0-M2</version>
           <executions>
              <execution>
                 <id>check-for-cert-file</id>
                 <phase>test-compile</phase>
                 <goals>
                    <goal>enforce</goal>
                 </goals>
                 <configuration>
                    <skip>${maven.test.skip}</skip>
                    <skip>${skipTests}</skip>
                    <rules>
                       <requireFilesExist>
                          <message>Download the files from the repo</message>
                          <files>
                             <file>/tmp/missingFile</file>
                          </files>
                       </requireFilesExist>
                    </rules>
                 </configuration>
              </execution>
           </executions>
        </plugin>

就像“ stackoverflow中的鸭子编程”一样。