<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Piyush Asutkar</title>
    <description>The latest articles on DEV Community by Piyush Asutkar (@asutkarpeeyush).</description>
    <link>https://dev.to/asutkarpeeyush</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F81046%2Fa97d4b0d-50a9-467c-871d-b2e94d70df8e.jpg</url>
      <title>DEV Community: Piyush Asutkar</title>
      <link>https://dev.to/asutkarpeeyush</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asutkarpeeyush"/>
    <language>en</language>
    <item>
      <title>Spring Webflux testing with Mockito</title>
      <dc:creator>Piyush Asutkar</dc:creator>
      <pubDate>Wed, 24 Feb 2021 06:43:52 +0000</pubDate>
      <link>https://dev.to/asutkarpeeyush/spring-webflux-testing-with-mockito-48em</link>
      <guid>https://dev.to/asutkarpeeyush/spring-webflux-testing-with-mockito-48em</guid>
      <description>&lt;p&gt;Spring Webflux provides fully non-blocking support for building web applications and Mockito is used to generate mock objects during testing. This article focuses on using Mockito alongside WebTestClient (client to test webflux server endpoints).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-requisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring Webflux&lt;/li&gt;
&lt;li&gt;Mockito&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A simple Webflux router configuration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;The Handler function that the router invokes:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Note: The router and handler in the webflux world act as rest controllers in the webmvc world.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Service that the handler invokes:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Note: Ideally, the service would interact with the DAO layer to retrieve the data. Keeping things simple to focus on mocking during the testing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Case:&lt;/strong&gt;&lt;br&gt;
This test case injects mocks into the handler layer, mocks the service layer and then uses WebTestClient to call the API.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We can also use PowerMockito in a similar way in conjunction with Webflux and Mockito.&lt;/p&gt;

&lt;p&gt;Further reading:&lt;br&gt;
&lt;a href="https://spring.getdocs.org/en-US/spring-framework-docs/docs/testing/integration-testing/webtestclient.html"&gt;https://spring.getdocs.org/en-US/spring-framework-docs/docs/testing/integration-testing/webtestclient.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webflux</category>
      <category>spring</category>
      <category>mockito</category>
      <category>reactive</category>
    </item>
  </channel>
</rss>
