views:

28

answers:

2

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?

+3  A: 

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.

Peter Tillemans
Can I do that but without tie the test data to the resource of one of the projects? Like having a project that does not have any java code but only the test data and use it as test dependency for any project that wants to test against this test data?
Paralife
I don't think that this is a good solution, you should NOT bundle a "large amount of test files" in the final artifact.
Pascal Thivent
What isnt a good solution? Bundling the large amount of test data with a real project, or generally bundling a large amount of test data as a project itself (a "test data only artifact") to be used with any other project as a test dependency?
Paralife
You will not bundle the data in the final artifact if the dependency is in the test scope. Then it is only used during testing and it will not be packaged. I recommend making such a test dependency if only to not have it in the checkout and the ability to version it so there is no confusion if it is shared between modules.
Peter Tillemans
@Peter My comment was not about scoping but about adding tests resources in the the `src/main/resources` folder of a "deliverable" artifact. I did not spot in your initial answer that you were suggesting to move the resources in another module. But maybe I just misunderstood, in which case my comment doesn't apply.
Pascal Thivent
@Pascal You are absolutely right, that point was unclear in my answer. I edited in the hope to clarify this point. Thank you.
Peter Tillemans
@Paralife: => Bundling the large amount of test data with a real project.
Pascal Thivent
Now I can upvote ;) This is indeed much simpler than the alternative I'm suggesting in this case. +1
Pascal Thivent
+2  A: 

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.

Pascal Thivent