I have class:
@Service
public class A {
@Value("${a.b.c}")
private String abc;
public void foo() {
sout(abc);
}
}
I Have test class:
@SpringBootTest
@SpringBootConfiguration
@RunWith(SpringRunner.class)
@TestPropertySource(locations = "classpath:application.yml")
public class TestA {
@Value("${a.b.c}")
private String abc;
@InjectMocks
private A a;
@Test
public void testFoo() {
this.a.foo();
}
}
When I debugging the test method testFoo()
,
I see that variable abc
is read from the application.yml
file.
But,
inside the foo()
method,
I see that the variable abc
is null.
How can I set variable abc
such that it is available in method foo()
when I trying to test this method?