我需要使用 Environment bean 在其中一个测试类中读取单元测试的属性,但是 spring 无法创建环境 bean。
@RunWith(SpringRunner.class)
@TestPropertySource(locations = "/application-test.properties")
public class CardTest {
@Autowired
Environment environment;
@Test
public void givenPropertyFetchesAndValidatesTheValue() {
String output = environment.getProperty("test");
assertThat(output).isEqualTo("502123");
}
}
错误:
原因:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.core.env.Environment]:指定的类是一个接口。
请帮忙