Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@TestPropertySource annotation alternative on a method level

@TestPropertySource(locations="classpath:test.properties")
public class Aclass {}

Is there an alternative that uses properties for the tested instance in a method.

@Test
public void aMethod(){}
like image 533
kidwon Avatar asked Mar 07 '16 13:03

kidwon


People also ask

What is @TestPropertySource?

@TestPropertySource is a class-level annotation that is used to configure the locations() of properties files and inlined properties() to be added to the Environment 's set of PropertySources for an ApplicationContext for integration tests.

How does Spring Boot read properties file in Test class?

You can use @TestPropertySource annotation in your test class. Just annotate @TestPropertySource("classpath:config/mailing. properties") on your test class. You should be able to read out the property for example with the @Value annotation.

Where does spring boot look for properties file in a test?

properties file in the classpath (src/main/resources/application. properties).


1 Answers

It is still not possible, but there is an open issue for this feature if you wish to follow it.

like image 73
Stav Shamir Avatar answered Sep 24 '22 08:09

Stav Shamir