2

I want to use junit with a spring context in order to write some integration tests.

These tests will just do a series of calls to rest endpoints and assert the responses. Somethink like what is described here but with a spring context in order to get what I need in unit test (like resttemplate and a user creation service). In order to not instantiate a context for each run I will use something like:

@ContextConfiguration(locations = {"classpath:test-context.xml"})
@RunWith(SpringJUnit4ClassRunner.class)

Because I have ContextConfiguration with the same context, this will stay cached during all tests run. I'm trying to add a yaml to this in order to have different envs (UAT, prod) but nothing I tried so far works. Is there a way to import the YML in context xml?

user1995187
  • 393
  • 5
  • 18
  • Looks like duplicate of https://stackoverflow.com/questions/28303758/how-to-use-yamlpropertiesfactorybean-to-load-yaml-files-using-spring-framework-4 – Ivan Jul 09 '19 at 20:15

1 Answers1

0

You can use @TestPropertySource to load different properties/yaml file

@TestPropertySource(locations="classpath:test.properties")

Usman Ali
  • 58
  • 4
  • this doesn't work; in the way that @Value fields don't get populated; if I move the yaml out of the classpath then it fails on startup – user1995187 Jul 10 '19 at 13:44