Неудачный тест с Spring WebFlux и контроллером - PullRequest
0 голосов
/ 03 февраля 2019

Я пытаюсь написать модульный тест для Spring Controller, используя Spring Webflux.Ниже приведен контроллер:

@Controller
public class MyController {

    private Service service;

    public MyController (Service service) {
        this.service=service;
    }

    @GetMapping({"", "/", "/index"})
    public String createChain(Model model) {
        model.addAttribute("blockchain", service.getString());

        return "index";
    }

}

Это базовый сервисный интерфейс:

public interface Service{

    Mono<String> getString();

}

А это тестовый класс:

@RunWith(SpringRunner.class)
@WebFluxTest(MyController.class)
public class MyControllerTest {

    @Autowired
    private WebTestClient webTestClient;

    @MockBean
    private Service service;

    @Test
    public void getAString() {

        BDDMockito.given(service.getString()).willReturn(Mono.just("A string."));

        this.webTestClient.get().uri("/").exchange()
                .expectStatus().isOk();

    }
}

Как вы можетевидите, я просто пытаюсь извлечь строку из реактивного сервиса, и я помещаю эту строку и шаблон HTML (я использую Thymeleaf в качестве механизма шаблонов).Тем не менее, я получаю следующее исключение:

java.lang.IllegalStateException: Не удалось разрешить представление с именем 'index'.в org.springframework.web.reactive.result.view.ViewResolutionResultHandler.lambda $ resolViews $ 3 (ViewResolutionResultHandler.java:276) ~ [spring-webflux-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в реакторе.core.publisher.FluxMapFuseable $ MapFuseableSubscriber.onNext (FluxMapFuseable.java:107) [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ MonoSubscriber.comjava (операторы: 1505) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoCollectList $ MonoBufferAllSubscriber.onComplete (MonoCollectList.java:118) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatMap $ ConcatMapImmediate.drain (FluxConcatMap.java:360) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] at реактор.core.publisher.FluxConcatMap $ ConcatMapImmediate.onComplete (FluxConcatMap.java:269) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] на реактор.core.publisher.Operators.complete(Operators.java:131) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxIterable.subscribe (FluxIterable.java:122) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxIterable.subscribe (FluxIterable.java: 63) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatMap.subscribe (FluxConcatMap.java:121) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoCollectList.subscribe (MonoCollectList.java:59) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] вреактор.core.publisher.MonoMapFuseable.subscribe (MonoMapFuseable.java:59) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoFlatMap.subscribe (MonoFlatMap.java: 60) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoFlatMap $ FlatMapMain.onNext (MonoFlatMap.java:150) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] at pipeline.core.publisher.FluxSwitchIfEmpty $ SwitchIfEmptySubscriber.onNext (FluxSwitchIfEmpty.java:67) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ ScalarSubscription.request (Operators.java:2070) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $MultiSubscriptionSubscriber.set (Operators.java:1878) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.[реактор-сердечник-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.3.2.5.RELEASE] в реакторе.core.publisher.MonoSwitchIfEmpty.subscribe (MonoSwitchIfEmpty.java:44) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoFlatMap.subscribe (MonoFlatMap.java:60) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoOnErrorResume.subscribe (MonoOnErrorResume.java:44) ~ реактор-core-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoFlatMap $ FlatMapMain.onNext (MonoFlatMap.java:150) ~ [реакторная зона-3.2.5.RELEASE.jar: 3.2.5.RELEASE] at processor.core.publisher.Operators $ MonoSubscriber.complete (Operators.java:1505) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE]at реактор.core.publisher.MonoFlatMap $ FlatMapInner.onNext (MonoFlatMap.java:241) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реактор.core.publisher.FluxOnErrorResume $ ResumeSumeonNext (FluxOnErrorResume.java:73) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxPeekFuseable $ PeekFuseableSubscriber.onNext (FluxPeekFuseable.java:20)-core-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxPeekFuseable $ PeekFuseableSubscriber.onNext (FluxPeekFuseable.java:204) ~ [реактор-ядро-3.2.5.RELEASE.jar:3.2.5.RELEASE] в реакторе.core.publisher.Operators $ MonoSubscriber.complete (Operators.java:1505) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] на реакторе.publisher.MonoIgnoreThen $ ThenAcceptInner.onNext (MonoIgnoreThen.java:296) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ MonoSubscriber.complete (Операторы.java1505FlatMapMain.onNext (MonoFlatMap.java:144) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ MonoSubscriber.complete (Operators.java:1505) ~[реактор-сердечник-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoZip $ ZipInner.onNext (MonoZip.java:329) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxPeekFuseable $ PeekFuseableSubscriber.onNext (FluxPeekFuseable.java:204) ~ [реактор-core-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ ScalarSubscription.java: 2070) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxPeekFuseable $ PeekFuseableSubscriber.request (FluxPeekFuseable.java:138) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] at processor.core.publisher.MonoZip $ ZipInner.onSubscribe (MonoZip.java:318) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.relEASE] at реактор.core.publisher.FluxPeekFuseable $ PeekFuseableSubscriber.onSubscribe (FluxPeekFuseable.java:172) ~ [реактор-core-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реактор.core.publisher.MonoJust.подписаться (MonoJust.java:54) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoPeekFuseable.subscribe (MonoPeekFuseable.java:74) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3695) ~ [реактор активной зоны-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoZip.subscribe (MonoZip.java:128) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoFlatMap.subscribe (MonoFlatMap.java:60) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoDefer.subscribe (MonoDefer.java:52) ~ [реактор-активной-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoIgnoreThen $ ThenIgnoreMain.drain (MonoIgnoreThen.java:153) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] на реакторе.er.MonoIgnoreThen.subscribe (MonoIgnoreThen.java:56) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoPeekFuseable.subscribe (MonoPeekFuseable.java:74) ~[реактор-сердечник-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.3.2.5.RELEASE] в реакторе.core.publisher.MonoOnErrorResume.subscribe (MonoOnErrorResume.java:44) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoFlatMap $ FlatMapMain.onNext (MonoFlatMap.java:150) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxSwitchIfEmpty $ SwitchIfEmptySubsberber.onNext (Flux)) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE]at processor.core.publisher.MonoNext $ NextSubscriber.onNext (MonoNext.java:76) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] вctor.core.publisher.FluxConcatMap $ ConcatMapImmediateinnerNext (FluxConcatMap.java:275) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatMap $ ConcatMapInner.onNext (FluxConcatMap.java:849) ~ [реактор-core-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxMapFuseable $ MapFuseableSubscriber.onNext (FluxMapFuseable.java:121) [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ ScalarSubscription.request (Operators.java:2070) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxMapFuseable $ MapFuseableSubscriber.request (FluxMapFuseable.java:162) [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ MultiSubscriptionSubscriber.set (Операторы.java:78) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Operators $ MultiSubscriptionSubscriber.onSubscribe (Operators.java:1752) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxMapFuseable $ MapFuseableSubscriber.onSubscribe (FluxMapFuseable.java:)реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoJust.subscribe (MonoJust.java:54) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoMapFuseable.subscribe (MonoMapFuseable.java:59) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3695) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatMap $ ConcatMapImmediate.drain (FluxConcatMap.java:442) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatMap $ ConcatMapImmediate.onSubscribe (FluxConcatMap.java:212) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxIterable.subscribe (FluxIterable.java:139) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxIterable.subscribe (FluxIterable.java:63) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatMap.subscribe (FluxConcatMap.java:121) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoNext.subscribe (MonoNext.java:40) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoSwitchIfEmpty.subscribe (MonoSwitchIfEmpty.java:44) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.кор.publisher.MonoFlatMap.subscribe (MonoFlatMap.java:60) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoFlatMap.subscribe (MonoFlatMap.java:60)~ [реактор-сердечник-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoDefer.subscribe (MonoDefer.java:52) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoDefer.subscribe (MonoDefer.java:52) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoOnErrorResume.subscribe (MonoOnErrorResume.java:44) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoPeekTerminal.subscribe (MonoPeekTerminal.java:61) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] at processor.core.publisher.MonoOnErrorResume.subscribe (MonoOnErrorResume.java:44) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE]at processor.core.publisher.Mono.subscribe (Mono.java:3695) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реактор.core.publisher.MonoIgnoreThen $ ThenIgnoreMain.drain (MonoIgnoreThen.java:172) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoIgnoreThen.subscribe (MonoIgnoreThen.java:56) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3695) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE]at processor.core.publisher.Mono.subscribeWith (Mono.java:3801) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] на реактор.core.publisher.Mono.subscribe (моно.java: 3689) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3656) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3628) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в орг.springframework.test.web.reactive.server.HttpHandlerConnector.lambda $ connect $ 1 (HttpHandlerConnector.java:89) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springframework.mock.http.client.reactive.MockClientHttpRequest.lambda $ null $ 2 (MockClientHttpRequest.java:121) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в реакторе.core.publisher.MonoDefer.sscribe(MonoDefer.java:44) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3695) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatIterable $ ConcatIterableSubscriber.onComplete (FluxConcatIterable.java:146) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.FluxConcatIterable.subscribe (FluxConcatIterable ~): 60[реактор-сердечник-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.MonoIgnoreElements.subscribe (MonoIgnoreElements.java:37) ~ [реактор-ядро-3.2.5.RELEASE.jar:3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3695) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribeWith (Mono.java:3801) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3689) ~ [реактор-core-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3656) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] в реакторе.core.publisher.Mono.subscribe (Mono.java:3628) ~ [реактор-ядро-3.2.5.RELEASE.jar: 3.2.5.RELEASE] на org.springframework.test.web.reactive.server.HttpHandlerConnector.connect (HttpHandlerConnector.java:100) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springframework.test.web.reactive.server.WiretapConnector.connect (WiretapConnector.java:71) ~[spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springframework.web.reactive.function.client.ExchangeFunctions $ DefaultExchangeFunction.exchange (ExchangeFunctions.java:103) ~ [spring-webflux-5.1.4.RELEASE.jar: 5.1.4.RELEASE] at org.springframework.web.reactive.function.client.DefaultWebClient $ DefaultRequestBodyUriSpec.exchange (DefaultWebClient.java:319) ~ [spring-webflux-5.1.4.RELEASE.jar: 5.1.4.RELEASE] at org.springframework.test.web.reactive.server.DefaultWebTestClient $ DefaultRequestBodyUriSpec.exchange (DefaultWebTestClient.java:283) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] at com.lorescianatico.driftcoin.controller.BlockChainControllerTest.createChain (BlockChainControllerTest.java:31) ~ [тестовые классы /: na] в sun.reflect.NativeMethodAccessorImpl.invoke0: N: (~): N (0_201] в sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) ~ [na: 1.8.0_201] at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) ~ [na: 1.8.0_201] локальный клиент java.invoke (Method.java:498) ~ [na: 1.8.0_201] в org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall (FrameworkMethod.java:50) ~ [junit-4.12.jar: 4.12] в org.junit.internal.runners.model.ReflectiveCallable.run (ReflectiveCallable.java:12) ~ [junit-4.12.jar: 4.12] в org.junit.runners.model.FrameworkMethod.invokeExplosively (FrameworkMethod.javait-47 ~ [FrameworkMethod.java:-47] [4.12.jar: 4.12] at org.junit.internal.runners.statements.InvokeMethod.evaluate (InvokeMethod.java:17) ~ [junit-4.12.jar: 4.12]в org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate (RunBeforeTestExecutionCallbacks.java:74) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springfrawork.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate (RunAfterTestExecutionCallbacks.java:84) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springframework.test.context.junit4.stateforebackeBB.evaluate (RunBeforeTestMethodCallbacks.java:75) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate (RunAfterCateback).86) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springframework.test.context.junit4.statements.SpringRepeat.evaluate (SpringRepeat.java:84) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.junit.runners.ParentRunner.runLeaf (ParentRunner.java:325) ~ [junit-4.12.jar: 4.12] в org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (SpringJUnit4ClassRunner.java:251) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.springframework.test.context.junit4.SpringJUnit4ClassRunner.junC (Spring) SpringJRunC) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:290) ~ [junit-4.12.jar: 4.12] вorg.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:71) ~ [junit-4.12.jar: 4.12] в org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288) ~ [junit-4.12.jar: 4.12] at org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:58) ~ [junit-4.12.jar: 4.12] at org.junit.runners.ParentRunner $ 2.оценка (ParentRunner.java:268)~ [junit-4.12.jar: 4.12] at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate (RunBeforeTestClassCallbacks.java:61) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate (RunAfterTestClassCallbacks.java:70) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE] в org.junit.runners.ParentRunner.run (ParentRunner.java:363) ~ [junit-4.12.jar: 4.12] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run (SpringJUnit4ClassRunner.java:190) ~ [spring-test-5.1.4.RELEASE.jar: 5.1.4.RELEASE]

Я не понимаю, в чем дело.Шаблон с именем index.html находится под src/main/resources/templates/index.html.

Спасибо за вашу поддержку!

1 Ответ

0 голосов
/ 03 февраля 2019

WebFluxTest : использование этой аннотации отключит полную автоконфигурацию и вместо этого будет применять только конфигурацию, относящуюся к тестам WebFlux (т. Е. Компоненты @Controller, @ControllerAdvice, @JsonComponent, Converter / GenericConverter и WebFluxConfigurerно не @Component, @Service или @Repository bean).

Если вы хотите загрузить полную конфигурацию приложения и использовать WebTestClient, вам следует рассматривать @SpringBootTest в сочетании с @AutoConfigureWebTestClient, а не эту аннотацию.

Документ WebFluxTest


@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureWebTestClient
public class MyControllerTest {

    @Autowired
    private WebTestClient webTestClient;

    @MockBean
    private Service service;

    @Test
    public void getAString() {

        BDDMockito.given(service.getString()).willReturn(Mono.just("A string."));

        this.webTestClient.get().uri("/").exchange()
                .expectStatus().isOk();

    }
}
...