Common test data for multiple independent maven projects

社会主义新天地 提交于 2019-12-21 05:33:16

问题


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.

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?

Any ideas?


回答1:


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

  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.




回答2:


Just place them in a tree in the src/main/resources directory of a separate module specially to share the test data. They will be added to the jar file and me nicely compressed and versioned in your nexus repository, file-share, ~/.m2/repository or whatever you use to store/distribute maven artifacts.

Then just add a dependency in the projects you need the data in the test scope and use resource loading to get them from the jars.

You do not need any special plugins or other infrastructure. This just works.



来源:https://stackoverflow.com/questions/2970120/common-test-data-for-multiple-independent-maven-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!