I have a simple bean
public class MyBean {
@Value("${propItem}")
private boolean propItem;
public String someMethod() {
if (propItem) {
return "XX";
} else {
return "XY";
}
}
}
I have a properties file in src/test/resources
called application-test.yml
which has one property
propItem: true
If I run my test below - I expect it to pass, but it fails because propItem
is always false
@SpringBootTest
public class MyBeanTest {
public void testFunc() {
assertTrue(new MyBean().someMethod().equals("XX"); // Fails because it's "XY"
}
}
Why is this a problem? I thought Spring does all these automatically, but seems not