2017-08-13 76 views
5

我有一个春天启动的项目和它的伟大工程。我现在想为我的应用程序编写测试,并且遇到一些配置问题。春天开机测试 - 找不到测试性能

春季启动创造了我的测试类叫做ApplicationTests。这是真实简单,它看起来像这样:

@RunWith(SpringRunner.class) 
@SpringBootTest 
public class DuurzaamApplicationTests { 
    @Test 
    public void contextLoads() { 
    }  
} 

现在,当我开始测试我得到这个错误:

java.lang.IllegalArgumentException: Could not resolve placeholder 'company.upload' in value "${company.upload}" 

我在src /测试/资源目录中的文件properties.yml和由于某种原因它没有加载。我已经尝试了来自互联网上的示例的所有不同类型的注释,但它们都不起作用。

我怎样才能知道春天开机测试使用application.yml文件从装载的属性?

回答

3

我们可以使用@TestPropertySource@PropertySource加载属性文件

@RunWith(SpringRunner.class) 
@SpringBootTest 
@TestPropertySource("classpath:properties.yml") 
@ActiveProfiles("test") 
public class DuurzaamApplicationTests { 
    @Test 
    public void contextLoads() { 
    }  
} 

文档:https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/context/TestPropertySource.html

+1

不工作。我仍然获得“价值无法解析占位符‘company.upload’‘$ {} company.upload’我有位于src /测试/资源目录的application.yml。 –

+0

你能共享项目在主旨或混帐? – Barath

+0

或在src /主/资源,默认情况下springboot定义应用程序test.yml值包括测试配置文件中运行测试 – Barath