No Binaries in the Codebase

Binary data shouldn't be a part of the codebase. This is pretty well-known practice. But how to proceed when we do need binaries in our codebase, for instance as test data?

The solution is straight-forward: Pack binary resources into an artifact separated from the codebase in a repository.

A good practice is to use a special classifier for all the artifacts of this kind, for instance testdata.

After uploading the resources artifact into a repository (manually or via an API), we can use it as a dependency in our codebase (Maven):


The Maven plugin will download and unpack the resources into the test classpath before the test are actually executed.

Binaries are then available in the codebase (Java):


Another good practice is to create a domain-based resources structure inside the artifacts. Just put the resources into a sub-folder:
┕ domainA/
  ┕ resource1.dat
  ┕ resource2.dat

This organization enables composition of resources in the integration testing.

The example code could be found in my GitHub.

Happy resourcing!