SpringJUnit4ClassRunner无法加载测试属性文件

huangapple 未分类评论57阅读模式
英文:

SpringJUnit4ClassRunner does not load the test properties file

问题

以下是翻译好的内容:

我正在尝试启动一个带有MapStruct实现的Spring Boot测试。我正在使用下面的配置,但是资源目录中的application.properties文件没有被读取到测试中。

如何使得下面的测试能够读取默认的属性文件?该文件存在于test/resources目录中,其他Spring Boot测试可以加载它。

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringBootExampleConfig.class)
public class SpringBootExampleTest {

    @Autowired
    private IMapper mapper;

    @Test
    public void test() {
    }

    @Configuration
    @ComponentScan(basePackageClasses = SpringBootExampleTest.class)
    public static class SpringTestConfig {
    }

}
英文:

I am trying to boot up a spring boot test, with a mapstruct implementation provided.
I am using the configuration below, but the application.properties file in the resources directory is not being read into the test.

How do I get the test below to read the default properties file, the file exist in test/resources and other spring boot tests are able to load it.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringBootExampleConfig.class)
public class SpringBootExampleTest {

    @Autowired
    private IMapper mapper;


    @Test
    public void test() {
    }

    @Configuration
    @ComponentScan(basePackageClasses = SpringBootExampleTest.class)
    public static class SpringTestConfig {
    }

}

huangapple
  • 本文由 发表于 2020年6月29日 17:10:18
  • 转载请务必保留本文链接:https://java.coder-hub.com/62634818.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定