Отказ тестового модуля - PullRequest
0 голосов
/ 08 апреля 2019

Я пытаюсь разрешить следующее исключение, сгенерированное в моей сборке Jenkins, из модульного теста для переопределения конфигурации обратного входа Spring Boot. Обратите внимание, что это исключение не возникает в IntelliJ .

Возможно ли, что Spring все еще пытается получить файл logback.xml по умолчанию?Я попытался удалить префикс classpath: из logging.config и использовать DirtiesContext безрезультатно.

Logging system failed to initialize using configuration from 'classpath:some/package/logback-test-sample.xml'
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@3:117 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:113 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:116 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:113 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:113 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@8:97 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)

Вот тест, вызывающий исключение

@SpringBootApplication
protected static class MyTest {
     public static void main(String... args) {
          SpringApplication.run(MyTest.class, args);
     }
}

@Test
public void myTest() {
     ClassPathResource properties = new ClassPathResource("some/package/logging.properties");
     Properties props = new Properties();
     props.load(properties.getInputStream());
     try (ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(props).profiles("some-profile").sources(MyTest.class).run()) {
            assertThat(applicationContext.getEnvironment().getProperty("logging.config")).isNotBlank().isEqualTo("classpath:some/package/logback-test-sample.xml");
     }
}

и file.properties

logging.config=classpath:some/package/logback-test-sample.xml
...