@TestPropertySource не работает для теста JUnit с AnnotationConfigContextLoader в Spring 1.2.6JAVA

Программисты JAVA общаются здесь
Anonymous
@TestPropertySource не работает для теста JUnit с AnnotationConfigContextLoader в Spring 1.2.6

Сообщение Anonymous »

Похоже, что все, что я делаю в Spring 4.1.17 с Spring Boot 1.2.6.RELEASE, вообще не работает. Я просто хочу получить доступ к свойствам приложения и при необходимости переопределить их с помощью теста (без использования хака для внедрения PropertySource вручную)

это не работает..

Код: Выделить всё

@TestPropertySource(properties = {"elastic.index=test_index"})
и это не так..

Код: Выделить всё

@TestPropertySource(locations = "/classpath:document.properties")
ни это..

Код: Выделить всё

@PropertySource("classpath:/document.properties")
полный тестовый пример..

Код: Выделить всё

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@TestPropertySource(properties = {"elastic.index=test_index"})
public class PropertyTests {
@Value("${elastic.index}")
String index;

@Configuration
@TestPropertySource(properties = {"elastic.index=test_index"})
static class ContextConfiguration {
}

@Test
public void wtf() {
assertEquals("test_index", index);
}
}
в результате

Код: Выделить всё

org.junit.ComparisonFailure:
Expected :test_index
Actual   :${elastic.index}
Похоже, что между версиями 3.x и 4.x существует много противоречивой информации, и я не могу найти ничего, что наверняка будет работать.

Будем благодарны за любую информацию. Ура!

Подробнее здесь: https://stackoverflow.com/questions/326 ... ontextload

Вернуться в «JAVA»