<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Mock on Micha Kops&#39; Tech Notes</title>
    <link>https://www.hascode.com/tags/mock/</link>
    <description>Recent content in Mock on Micha Kops&#39; Tech Notes</description>
    <generator>Hugo -- 0.147.8</generator>
    <language>en</language>
    <copyright>Copyright © 2010 - 2025 Micha Kops. #213243b1d6e8932079e09227d3f3ed0c806cd0c9</copyright>
    <lastBuildDate>Fri, 04 Jun 2021 00:00:00 +0200</lastBuildDate>
    <atom:link href="https://www.hascode.com/tags/mock/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Writing a React Component Test with Jest and Testing Library</title>
      <link>https://www.hascode.com/writing-a-react-component-test-with-jest-and-testing-library/</link>
      <pubDate>Fri, 04 Jun 2021 00:00:00 +0200</pubDate>
      <guid>https://www.hascode.com/writing-a-react-component-test-with-jest-and-testing-library/</guid>
      <description>&lt;div id=&#34;preamble&#34;&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;sidebarblock&#34;&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;div class=&#34;title&#34;&gt;Goals&lt;/div&gt;
&lt;div class=&#34;olist arabic&#34;&gt;
&lt;ol class=&#34;arabic&#34;&gt;
&lt;li&gt;
&lt;p&gt;render a React component in a test&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;mock HTTP/REST calls to the backend&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;verify results&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;achieve the above using typescript, jest and testing-library&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;sect1&#34;&gt;
&lt;h2 id=&#34;_application_under_test&#34;&gt;Application under Test&lt;/h2&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;This is our application’s shortened &lt;code&gt;package.json&lt;/code&gt;, generated by &lt;a href=&#34;https://create-react-app.dev/docs/getting-started/&#34;&gt;create-react-app&lt;/a&gt;, adding dependencies for …​&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;ulist&#34;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;jest&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;testing-library&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;typescript&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;react&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;dom implementations (jest-dom/react-dom)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;axios (for the HTTP/REST call)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&#34;listingblock&#34;&gt;
&lt;div class=&#34;title&#34;&gt;package.json&lt;/div&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;pre class=&#34;highlight&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;{
  [..]
  &amp;#34;dependencies&amp;#34;: {
    &amp;#34;@testing-library/jest-dom&amp;#34;: &amp;#34;^5.11.4&amp;#34;,
    &amp;#34;@testing-library/react&amp;#34;: &amp;#34;^11.1.0&amp;#34;,
    &amp;#34;@testing-library/user-event&amp;#34;: &amp;#34;^12.1.10&amp;#34;,
    &amp;#34;@types/jest&amp;#34;: &amp;#34;^26.0.15&amp;#34;,
    &amp;#34;@types/node&amp;#34;: &amp;#34;^12.0.0&amp;#34;,
    &amp;#34;@types/react&amp;#34;: &amp;#34;^17.0.0&amp;#34;,
    &amp;#34;@types/react-dom&amp;#34;: &amp;#34;^17.0.0&amp;#34;,
    &amp;#34;react&amp;#34;: &amp;#34;^17.0.2&amp;#34;,
    &amp;#34;react-dom&amp;#34;: &amp;#34;^17.0.2&amp;#34;,
    &amp;#34;react-scripts&amp;#34;: &amp;#34;4.0.3&amp;#34;,
    &amp;#34;typescript&amp;#34;: &amp;#34;^4.1.2&amp;#34;,
    &amp;#34;web-vitals&amp;#34;: &amp;#34;^1.0.1&amp;#34;,
    &amp;#34;axios&amp;#34;: &amp;#34;^0.19.0&amp;#34;
  },
  [..]
  &amp;#34;eslintConfig&amp;#34;: {
    &amp;#34;extends&amp;#34;: [
      &amp;#34;react-app&amp;#34;,
      &amp;#34;react-app/jest&amp;#34;
    ]
  },
  [..]
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <title>Template Driven Test POJO Generation with Fixture Factory and Java</title>
      <link>https://www.hascode.com/template-driven-test-pojo-generation-with-fixture-factory-and-java/</link>
      <pubDate>Tue, 20 Jun 2017 00:00:00 +0200</pubDate>
      <guid>https://www.hascode.com/template-driven-test-pojo-generation-with-fixture-factory-and-java/</guid>
      <description>&lt;div id=&#34;preamble&#34;&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;In our tests we often need to create a bunch of test-objects that are populated with random-data. This data needs to follow specific rules as identifiers need to be unique or must be incremented, string-properties must follow special conventions and so on. In the following short tutorial I will demonstrate how to generate such test data using the Fixture Factory library.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;imageblock&#34;&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;img src=&#34;fixture-factory-running-with-junit-in-intellij-1024x752.png&#34; alt=&#34;fixture factory running with junit in intellij 1024x752&#34;/&gt;
&lt;/div&gt;
&lt;div class=&#34;title&#34;&gt;Figure 1. Fixture Factory and JUnit&lt;/div&gt;</description>
    </item>
    <item>
      <title>Mocking HTTP Interaction with Java, JUnit and MockServer</title>
      <link>https://www.hascode.com/mocking-http-interaction-with-java-junit-and-mockserver/</link>
      <pubDate>Tue, 05 Jan 2016 00:00:00 +0100</pubDate>
      <guid>https://www.hascode.com/mocking-http-interaction-with-java-junit-and-mockserver/</guid>
      <description>&lt;div id=&#34;preamble&#34;&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;When writing tests for our software components sometimes we need to mock external services based on the HTTP protocol, might it be a RESTful web-service, an XML-RPC call or a simple GET request to some web-server.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;In the following short tutorial I’d like to demonstrate how to create a mock HTTP server for testing and how to bootstrap and bind it to the life-cycle of a classical build-management tool like Maven.&lt;/p&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <title>Mocking, Stubbing and Test Spying using the Mockito Framework and PowerMock</title>
      <link>https://www.hascode.com/mocking-stubbing-and-test-spying-using-the-mockito-framework-and-powermock/</link>
      <pubDate>Sun, 27 Mar 2011 00:00:00 +0100</pubDate>
      <guid>https://www.hascode.com/mocking-stubbing-and-test-spying-using-the-mockito-framework-and-powermock/</guid>
      <description>&lt;div id=&#34;preamble&#34;&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;imageblock&#34;&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;img src=&#34;mockito-tutorial.png&#34; alt=&#34;mockito tutorial&#34;/&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;Today we’re going to take a look at the Mockito framework that not only does sound like my favourite summer cocktail but also offers nice testing, mocking/stubbing, test-spying features and mock injections.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;After that we’re going to take a look on how to mock static or final classes by extending Mockito’s capabilities with PowerMock.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;sect1&#34;&gt;
&lt;h2 id=&#34;_prerequisites&#34;&gt;Prerequisites&lt;/h2&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;We don’t need much for the following samples .. Java of course, Maven dependency management and that’s all ..&lt;/p&gt;
&lt;/div&gt;</description>
    </item>
  </channel>
</rss>
