多个独立Maven项目的通用测试数据

多个独立Maven项目的通用测试数据

问题描述:

我有一个Maven项目,可以将特定格式的文本文件转换为另一种格式. 为了进行测试,我在src/test/resources中放入了大量测试文件.

I have a maven project that converts text files of a specific format to another format. For testing I have put in src/test/resources a large amount of test files.

我还有另一个项目,该项目使用第一个项目进行转换,然后在输出格式上做一些额外的工作.我也想针对相同的测试数据集测试该项目,但是我不想有重复的数据集,并且我希望能够单独测试第一个项目,因为它也是一个独立的转换器项目.

I also have another project that uses the first one to do the conversion and then do some extra stuff on the output format. I also want to test this project against the same test dataset, but I dont want to have duplicate data sets and I want to be able to test the first project alone since it is also a standalone converter project.

有什么通用的解决方案吗?我不介意在项目源代码树中没有测试数据集,只要每个项目可以独立访问另一个项目的数据集即可.我也不想为此建立数据库.我在想像是比RDBMS更简单的测试数据存储库.是否可以针对特定的Maven插件使用任何此类需求的应用程序?易于设置和简化是我的首要任务.我也在想一些类似打包测试数据并将其放入内部Maven存储库中,然后下载并将其解压缩到junit代码中的事情.或者更好的是,有一个Maven插件可以为我做到这一点吗?

Is there any common solution for doing that? I dont mind not having the test dataset inside the projects source tree as long as each project can access the data set independently of the other. I dont want to setup a database for that also. I am thinking something like a repository of test data simpler than an RDBMS. Is there any application for this kind of need that I can use with a specific maven plugin? Ease of setup and simplicity is my priority. Also I m thinking something like packaging the test data and putting it in a internal maven repo and then downloading it and unzip it in the junit code. Or better, is there a maven plugin that can do this for me?

有什么想法吗?

可以与Maven共享资源,例如在依赖性插件.基本上:

It is possible to share resources with Maven, for example with the help of the Assembly and Dependency plugins. Basically:

  1. 创建一个包装类型为pom的模块以容纳共享资源
  2. 使用Assembly插件将模块打包为zip
  3. 在消费者"模块中声明对此zip的依赖性
  4. 并使用 dependency:unpack-dependencies (加上一些排除规则)以解压缩zip
  1. Create a module with a packaging of type pom to hold the shared resources
  2. Use the assembly plugin to package the module as a zip
  3. Declare a dependency on this zip in "consumer" modules
  4. And use dependency:unpack-dependencies (plus some exclusion rules) to unpack the zip

This approach is detailed in How to share resources across projects in Maven. It requires a bit of setup (which is "provided") and is not too complicated.