无法从JUnit的属性文件中加载值

时间:2018-11-10 09:52:59

标签: junit junit4

这是我的测试文件,我无法从属性文件中插入值

@RunWith(MockitoJUnitRunner.class)
@ContextConfiguration(classes = VersionResourceImplTest.myProp.class)
@TestPropertySource(properties = {"ra.bank.app.version=TestVersion"})
public class VersionResourceImplTest {

    @Value("${ra.bank.app.version}")
    private String applicationVersion;

    @Test
    public void testVersion() {
        Assert.assertEquals("TestVersion", applicationVersion);
    }

    @Configuration
    public static class myProp{
        @Bean
        public static PropertySourcesPlaceholderConfigurer propertiesResolver()
        {
            return new PropertySourcesPlaceholderConfigurer();
        }
    }
}

获取错误:测试失败:

VersionResourceImplTest.testVersion:36 expected:<TestVersion> but was:<null>
Not able to fetch values from property file

0 个答案:

没有答案