0

The unit test class defined in src/test/... starts with:

@SpringBootTest
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes={MyProperties.class})
public class ConnectionTest {

    @Autowired
    MyProperties props;
// ...

The MyProperties.class is defined in src/main/...:

@ConfigurationProperties(prefix = "app")
public final class MyProperties {

    @NotEmpty private String name;
// ...

When the MyProperties is injected in src/main/... then the values which it has are taken from src/resources/application.properties file.

But when the MyProperties is injected in src/test/... as I shown above then the values are null.

Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59
  • Try adding `@Component` to the `MyProperties` class – rdas Mar 28 '20 at 22:15
  • `Parameter 1 of method ... in ... required a single bean, but 2 were found: myProperties defined in ... and myProperties defined in null` – tester01020304 Mar 28 '20 at 22:24
  • Try to add @EnableAutoConfigurationProperties above ConnectionTest – OHY Mar 28 '20 at 22:31
  • see my answer here https://stackoverflow.com/questions/48111941/spring-boot-application-test-properties/48114025#48114025 This has the solution – pvpkiran Mar 29 '20 at 20:24

0 Answers0