Search code examples
javaunit-testingresourcesmockingdirectory-structure

Where to store a binary file to be used for unit testing


Where should I store a resource (binary file in my case) that I need to use for unit testing?

Specifically, my directory structure is a standard:

src -> main -> java -> com.company.project -> classes...
    -> test -> java -> com.company.project -> classes...

I want to mock a file being read from the file system and replace it with a file from within my project.


Solution

  • src\test\resources is a good place for resources you need for unit-testing, if you are using mavens standard directory layout.

    Read more about the different directories here: https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html