0

My test class is:

@RunWith(MockitoJUnitRunner.class)
@TestPropertySource
public class FooClassTest {

    @Value("${foo.property}")
    String property;

    ...
}

In my application properties, inside test/resources folder, I have the property foo.property=some, but when I launch FooClassTest, property is null.

What I am doing wrong?

1 Answer 1

1

Remove the @TestPropertySource if you refer to the documenation (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/TestPropertySource.html) it states

@TestPropertySource is a class-level annotation that is used to configure the locations() of properties files and inlined properties()....

It also states

Test property sources have higher precedence than those loaded from the operating system's environment or Java system properties as well as property sources added by the application declaratively

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.