Добавление @SpringBootTest для тестирования модульных тестов зависания класса - PullRequest
0 голосов
/ 16 марта 2020

Я хочу проверить мое приложение Spring. Когда я добавляю @SpringBootTest в свой тестовый класс, тесты зависают и не запускаются, даже если я жду больше часа! Удаление моей аннотации SpringBootTest приводит к ошибке инициализации полей @Value, и я не могу проверить ни один из моих классов компонентов. Код класса My Configuration:

@ConditionalOnProperty(value = "app.scheduling.enable", havingValue = "true", matchIfMissing = true)
@Configuration
@EnableScheduling
public class Configurer {    
private static ApplicationContext context = new AnnotationConfigApplicationContext("ir.isc.nps.ach.pasha");
    public static ApplicationContext getContext() {
        return context;
    }
}

Класс My Test:

@SpringBootTest
@ContextConfiguration(classes = Configurer.class)
@TestPropertySource("classpath:application.properties")
public class ConfigurerTest {
    @Test
    void getContext() {
        assertNotNull(Configurer.getContext());
    }
}

трассировка стека во время выполнения класса теста:

12:15:41.488 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@1a18644 testClass = PashaApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@5acf93bb testClass = PashaApplicationTests, locations = '{}', classes = '{class ir.isc.nps.ach.pasha.Configurer}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{classpath:application.properties}', propertySourceProperties = '{jobs.enable.scheduler=true, cron.expression=* * * ? * *, app.scheduling.enable=true, thread.poolCount=32, inputFile.dir=/TestResources, acceptedFolder.dir=\accepted, errorFolder.dir=\error, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@7e0b85f9, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@6a28ffa4, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@72f926e6, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@7714e963], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
12:15:41.567 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, jobs.enable.scheduler=true, cron.expression=* * * ? * *, app.scheduling.enable=true, thread.poolCount=32, inputFile.dir=/TestResources, acceptedFolder.dir=\accepted, errorFolder.dir=\error, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
2020-03-16 12:15:41 INFO  i.i.n.a.Tests - Starting Tests on  with PID (started by  in )
2020-03-16 12:15:41 INFO  i.i.n.a.Tests - No active profile set, falling back to default profiles: default
2020-03-16 12:15:43 INFO  o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-16 12:15:43 INFO  o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 94ms. Found 6 JPA repository interfaces.

Тест зависает при запуске это:

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...