how can I do an Unit Test below code using WebFlux and Java 8?
I want to create a Unit Test this code using WebFlux but I don't know how to do that, I need to cover 100% call method below in the unit test.
@Autowired
private WebClient webClient;
public String call(final String xml)
return this.webClient.post().uri("URL")
.contentType(MediaType.APPLICATION_XML)
.body(Mono.just(xml),String.class)
.retrieve()
.bodyToMono(String.class)
.block();
thank you so how much who can help me
unit-testing spring-boot spring-webflux
add a comment |
I want to create a Unit Test this code using WebFlux but I don't know how to do that, I need to cover 100% call method below in the unit test.
@Autowired
private WebClient webClient;
public String call(final String xml)
return this.webClient.post().uri("URL")
.contentType(MediaType.APPLICATION_XML)
.body(Mono.just(xml),String.class)
.retrieve()
.bodyToMono(String.class)
.block();
thank you so how much who can help me
unit-testing spring-boot spring-webflux
Possible duplicate of Spring WebFlux, unit testing Mono and Flux
– Emre Savcı
Aug 25 '18 at 6:58
it is not duplicate question @EmreSavcı
– Lewis Florez R
Aug 29 '18 at 5:06
You can use WebTestClient, check here callicoder.com/… .. and also StepVerifier is possible, read here: projectreactor.io/docs/core/release/reference/docs/…
– vanillaSugar
Sep 5 '18 at 7:34
Just a note on the code: The "block()" in the end smells a bit, since you don't really win anything by using a reactive webclient, if you're leaving the reactive world right at the end of the method.
– Frischling
Sep 6 '18 at 7:23
@Frischling I need that method return a string value.
– Lewis Florez R
Nov 13 '18 at 3:44
add a comment |
I want to create a Unit Test this code using WebFlux but I don't know how to do that, I need to cover 100% call method below in the unit test.
@Autowired
private WebClient webClient;
public String call(final String xml)
return this.webClient.post().uri("URL")
.contentType(MediaType.APPLICATION_XML)
.body(Mono.just(xml),String.class)
.retrieve()
.bodyToMono(String.class)
.block();
thank you so how much who can help me
unit-testing spring-boot spring-webflux
I want to create a Unit Test this code using WebFlux but I don't know how to do that, I need to cover 100% call method below in the unit test.
@Autowired
private WebClient webClient;
public String call(final String xml)
return this.webClient.post().uri("URL")
.contentType(MediaType.APPLICATION_XML)
.body(Mono.just(xml),String.class)
.retrieve()
.bodyToMono(String.class)
.block();
thank you so how much who can help me
unit-testing spring-boot spring-webflux
unit-testing spring-boot spring-webflux
edited Sep 5 '18 at 15:30
Lewis Florez R
asked Aug 24 '18 at 22:04
Lewis Florez RLewis Florez R
2115
2115
Possible duplicate of Spring WebFlux, unit testing Mono and Flux
– Emre Savcı
Aug 25 '18 at 6:58
it is not duplicate question @EmreSavcı
– Lewis Florez R
Aug 29 '18 at 5:06
You can use WebTestClient, check here callicoder.com/… .. and also StepVerifier is possible, read here: projectreactor.io/docs/core/release/reference/docs/…
– vanillaSugar
Sep 5 '18 at 7:34
Just a note on the code: The "block()" in the end smells a bit, since you don't really win anything by using a reactive webclient, if you're leaving the reactive world right at the end of the method.
– Frischling
Sep 6 '18 at 7:23
@Frischling I need that method return a string value.
– Lewis Florez R
Nov 13 '18 at 3:44
add a comment |
Possible duplicate of Spring WebFlux, unit testing Mono and Flux
– Emre Savcı
Aug 25 '18 at 6:58
it is not duplicate question @EmreSavcı
– Lewis Florez R
Aug 29 '18 at 5:06
You can use WebTestClient, check here callicoder.com/… .. and also StepVerifier is possible, read here: projectreactor.io/docs/core/release/reference/docs/…
– vanillaSugar
Sep 5 '18 at 7:34
Just a note on the code: The "block()" in the end smells a bit, since you don't really win anything by using a reactive webclient, if you're leaving the reactive world right at the end of the method.
– Frischling
Sep 6 '18 at 7:23
@Frischling I need that method return a string value.
– Lewis Florez R
Nov 13 '18 at 3:44
Possible duplicate of Spring WebFlux, unit testing Mono and Flux
– Emre Savcı
Aug 25 '18 at 6:58
Possible duplicate of Spring WebFlux, unit testing Mono and Flux
– Emre Savcı
Aug 25 '18 at 6:58
it is not duplicate question @EmreSavcı
– Lewis Florez R
Aug 29 '18 at 5:06
it is not duplicate question @EmreSavcı
– Lewis Florez R
Aug 29 '18 at 5:06
You can use WebTestClient, check here callicoder.com/… .. and also StepVerifier is possible, read here: projectreactor.io/docs/core/release/reference/docs/…
– vanillaSugar
Sep 5 '18 at 7:34
You can use WebTestClient, check here callicoder.com/… .. and also StepVerifier is possible, read here: projectreactor.io/docs/core/release/reference/docs/…
– vanillaSugar
Sep 5 '18 at 7:34
Just a note on the code: The "block()" in the end smells a bit, since you don't really win anything by using a reactive webclient, if you're leaving the reactive world right at the end of the method.
– Frischling
Sep 6 '18 at 7:23
Just a note on the code: The "block()" in the end smells a bit, since you don't really win anything by using a reactive webclient, if you're leaving the reactive world right at the end of the method.
– Frischling
Sep 6 '18 at 7:23
@Frischling I need that method return a string value.
– Lewis Florez R
Nov 13 '18 at 3:44
@Frischling I need that method return a string value.
– Lewis Florez R
Nov 13 '18 at 3:44
add a comment |
2 Answers
2
active
oldest
votes
You can't really unit test this, you'd have to do an integration test. Spin up your own Webserver, serving the content that helps in your test. At least that's my only idea for this.
Take a look at this here:
https://mock-server.com/mock_server/running_mock_server.html
add a comment |
Mocking the WebClient
using a library like mockito
is your best bet if you want to unit test this, but the function looks more deserving of an integration test as you'd really only be testing the mock's functionality at that point.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52012253%2fhow-can-i-do-an-unit-test-below-code-using-webflux-and-java-8%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't really unit test this, you'd have to do an integration test. Spin up your own Webserver, serving the content that helps in your test. At least that's my only idea for this.
Take a look at this here:
https://mock-server.com/mock_server/running_mock_server.html
add a comment |
You can't really unit test this, you'd have to do an integration test. Spin up your own Webserver, serving the content that helps in your test. At least that's my only idea for this.
Take a look at this here:
https://mock-server.com/mock_server/running_mock_server.html
add a comment |
You can't really unit test this, you'd have to do an integration test. Spin up your own Webserver, serving the content that helps in your test. At least that's my only idea for this.
Take a look at this here:
https://mock-server.com/mock_server/running_mock_server.html
You can't really unit test this, you'd have to do an integration test. Spin up your own Webserver, serving the content that helps in your test. At least that's my only idea for this.
Take a look at this here:
https://mock-server.com/mock_server/running_mock_server.html
edited Nov 15 '18 at 14:23
answered Nov 15 '18 at 14:13
FrischlingFrischling
565317
565317
add a comment |
add a comment |
Mocking the WebClient
using a library like mockito
is your best bet if you want to unit test this, but the function looks more deserving of an integration test as you'd really only be testing the mock's functionality at that point.
add a comment |
Mocking the WebClient
using a library like mockito
is your best bet if you want to unit test this, but the function looks more deserving of an integration test as you'd really only be testing the mock's functionality at that point.
add a comment |
Mocking the WebClient
using a library like mockito
is your best bet if you want to unit test this, but the function looks more deserving of an integration test as you'd really only be testing the mock's functionality at that point.
Mocking the WebClient
using a library like mockito
is your best bet if you want to unit test this, but the function looks more deserving of an integration test as you'd really only be testing the mock's functionality at that point.
answered Nov 15 '18 at 14:30
austinceaustince
367517
367517
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52012253%2fhow-can-i-do-an-unit-test-below-code-using-webflux-and-java-8%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Spring WebFlux, unit testing Mono and Flux
– Emre Savcı
Aug 25 '18 at 6:58
it is not duplicate question @EmreSavcı
– Lewis Florez R
Aug 29 '18 at 5:06
You can use WebTestClient, check here callicoder.com/… .. and also StepVerifier is possible, read here: projectreactor.io/docs/core/release/reference/docs/…
– vanillaSugar
Sep 5 '18 at 7:34
Just a note on the code: The "block()" in the end smells a bit, since you don't really win anything by using a reactive webclient, if you're leaving the reactive world right at the end of the method.
– Frischling
Sep 6 '18 at 7:23
@Frischling I need that method return a string value.
– Lewis Florez R
Nov 13 '18 at 3:44