如何从“application-test.properties”之类的文件中加载测试属性?
该文件存储在 src/test/resources 文件夹中。我也将文件放在所有可能的文件夹中。当作为 Maven 测试运行的一部分运行测试时,一切正常。从(IntelliJ)IDE 运行新的(单个)测试时,每次我收到相同的错误消息:
原因:java.io.FileNotFoundException:类路径资源[application-test.properties]无法打开,因为它不存在
这是测试类:
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
@ComponentScan(basePackages = {"nl.deholtmans.tjm1706.todolist"})
@PropertySource( "application-test.properties")
public class TodoListServiceTest {
@Autowired
TodoListService todoListService;
@Test
public void testBasic() { ... }
看来我必须第一次从 Maven 运行测试。这是为什么?