<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>devkuma – TDD</title>
    <link>https://www.devkuma.com/en/tags/tdd/</link>
    <image>
      <url>https://www.devkuma.com/en/tags/tdd/logo/180x180.jpg</url>
      <title>TDD</title>
      <link>https://www.devkuma.com/en/tags/tdd/</link>
    </image>
    <description>Recent content in TDD on devkuma</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>kc@example.com (kc kim)</managingEditor>
    <webMaster>kc@example.com (kc kim)</webMaster>
    <copyright>The devkuma</copyright>
    
	  <atom:link href="https://www.devkuma.com/en/tags/tdd/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>TDD(Test Driven Development)</title>
      <link>https://www.devkuma.com/en/docs/testing/tdd/</link>
      <pubDate>Thu, 30 Sep 2021 14:47:00 +0900</pubDate>
      <author>kc@example.com (kc kim)</author>
      <guid>https://www.devkuma.com/en/docs/testing/tdd/</guid>
      <description>
        
        
        &lt;h2 id=&#34;what-is-tddtest-driven-development&#34;&gt;What Is TDD(Test Driven Development)?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Test-driven development.&lt;/li&gt;
&lt;li&gt;It is a development method in which you first write test code, run tests with it, and proceed while receiving feedback on whether the code works correctly.&lt;/li&gt;
&lt;li&gt;It is a development process that depends on repeating short development cycles. Developers first write test cases for the required feature, write code that satisfies them, pass the tests, and then refactor as appropriate.&lt;/li&gt;
&lt;li&gt;Because developers must clearly understand the requirements of a feature in order to write tests, TDD helps them focus on requirements before development. However, the entry barrier for testing and the increase in code that must be written are considered disadvantages.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;what-is-a-mock&#34;&gt;What Is a Mock?&lt;/h2&gt;
&lt;p&gt;A mock is a fake object created when using a real object is costly or when high dependency between objects makes implementation difficult.&lt;/p&gt;
&lt;h2 id=&#34;examples-of-mock-usage&#34;&gt;Examples of Mock Usage&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Building an environment for writing tests&lt;/li&gt;
&lt;li&gt;When a test depends on a specific case or moment&lt;/li&gt;
&lt;li&gt;When a test takes a long time&lt;/li&gt;
&lt;li&gt;When operation may take a long time because of performance limitations on a personal PC or server&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;what-is-mockito&#34;&gt;What Is Mockito?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Mockito is a Java mocking framework for unit testing.&lt;/li&gt;
&lt;li&gt;It is a test framework that supports mock objects in Java unit tests.&lt;/li&gt;
&lt;li&gt;In other words, it is a framework that creates mocks for unit testing.&lt;/li&gt;
&lt;li&gt;It can create mock objects, define mock object behavior, and verify whether the logic under test was performed correctly.&lt;/li&gt;
&lt;li&gt;In general, when developing a web application such as one based on Spring, dependencies exist between multiple objects. These dependencies make unit tests difficult to write, and Mockito can be used to inject fake objects to solve this problem.&lt;/li&gt;
&lt;li&gt;By using Mockito, you can stub the desired results on fake objects and perform unit testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;dependency-injection-for-mock-objects&#34;&gt;Dependency Injection for Mock Objects&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Mockito mainly uses three annotations for dependency injection of mock objects.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@Mock&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;An annotation that creates and returns a mock object.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@Spy&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;An annotation that uses the original methods as-is for methods that have not been stubbed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@InjectMocks&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;An annotation that automatically injects fake objects created with &lt;code&gt;@Mock&lt;/code&gt; or &lt;code&gt;@Spy&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For example, when writing a unit test for &lt;code&gt;UserController&lt;/code&gt;, if it uses &lt;code&gt;UserService&lt;/code&gt;, you can create a fake &lt;code&gt;UserService&lt;/code&gt; with the &lt;code&gt;@Mock&lt;/code&gt; annotation and inject it into &lt;code&gt;UserController&lt;/code&gt; with &lt;code&gt;@InjectMocks&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
      
      <category>TDD</category>
      
      <category>Testing</category>
      
    </item>
    
  </channel>
</rss>
