Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share resources between test and main?

I'm working on a web application.

This is my project structure

src/
├── main
│   ├── java
│   ├── resources
│   └── webapp
└── test
    ├── java
    └── resources

In my tests I want to call a method from a class in java which uses a file in resources.

So I want to know how to share my resources between main and test?

I don't want to copy files to test-resources every time I edit them.

I tried SymLink but got an error 'Can't copy to test-classes because file does not exist.`

And this is how I access a resource in case it matters

class.getResourceAsStream("/data.yml");

EDIT


So, apparently Maven do share resources between main and test by default but it's not the case here.

When I build I can see my resources from main under target/classes but nothing in target/test-classes.

like image 449
Raghav Sharma Avatar asked Dec 29 '15 17:12

Raghav Sharma


1 Answers

Files present in main are visible in test.

So you can put resources on the main tree if necessary for both tests and main.

If the resources are necessary only for the test put them on the test subtree.

like image 77
Davide Lorenzo MARINO Avatar answered Oct 02 '22 00:10

Davide Lorenzo MARINO