dimanche 8 mars 2015

Loading the same properties(yml) files in testing enviornment?

I am trying to figure out whether I can load the same .yml property files in testing environment as I load in real.


For example I have a test:



\src\test\java\security\TokenTest.java


Annotated with:



@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("dev")


Then I have:



\src\main\resources\application.yml


When I run the application, the environment picks up property-source from the yml location.


Whenever I run my test, the environment does not see this file - i.e. property-source is not created/populated.


The obvious solution is to put duplicate file to the test location:



\src\test\resources\application.yml


And it will load, but that is bad - in terms that it raises unnecessary confusion when perceiving the difference between test and main resources.


This previous problem gets enhanced if you have configuration file per environment.


Is there a way to load resources from src/main/resources for tests?


This is probably some basic classpath scanning concept which I don't know.


My case is that I already faced the nightmare when you have 5 yml properties files per enviornment in src/main/resources and then you have 5 corresponding yml properties files in src/test/resources and someone from your team WILL 100 % at some point introduce discrepancy between them making everyone else bleed in the long term.


So by any means tests must refer to the same configuration files not to be the lost within its own void context.


Aucun commentaire:

Enregistrer un commentaire