<?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>Spring Builders: Michael Isvy</title>
    <description>The latest articles on Spring Builders by Michael Isvy (@michael_isvy_13067a826322).</description>
    <link>https://springbuilders.dev/michael_isvy_13067a826322</link>
    <image>
      <url>https://springbuilders.dev/images/ZhKLkrqk7JqpCo6IMLlsKvK3OAN5VCk2gPXCplDxaFw/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly9zcHJp/bmdidWlsZGVycy5k/ZXYvdXBsb2Fkcy91/c2VyL3Byb2ZpbGVf/aW1hZ2UvMy9mY2Mx/NTcyZC1iMzYzLTRj/M2ItOGNiNC02OTUz/OThlNWM2YTAucG5n</url>
      <title>Spring Builders: Michael Isvy</title>
      <link>https://springbuilders.dev/michael_isvy_13067a826322</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://springbuilders.dev/feed/michael_isvy_13067a826322"/>
    <language>en</language>
    <item>
      <title>Do you clean up after you're done?</title>
      <dc:creator>Michael Isvy</dc:creator>
      <pubDate>Tue, 14 May 2024 09:55:47 +0000</pubDate>
      <link>https://springbuilders.dev/michael_isvy_13067a826322/do-you-clean-up-after-youre-done-nma</link>
      <guid>https://springbuilders.dev/michael_isvy_13067a826322/do-you-clean-up-after-youre-done-nma</guid>
      <description>&lt;p&gt;Hello, &lt;br&gt;
I think we're all used to using @Transactional inside our JUnit tests, so the database can remain in a clean state.&lt;/p&gt;

&lt;p&gt;This article takes a different position, saying that each test should use some unique data, and therefore you don't need to rollback after a test: &lt;a href="https://arialdomartini.github.io/when-im-done-i-dont-clean-up"&gt;https://arialdomartini.github.io/when-im-done-i-dont-clean-up&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wondering if anybody follows those practices?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why do we need to use @Autowired inside Spring Boot Tests?</title>
      <dc:creator>Michael Isvy</dc:creator>
      <pubDate>Sun, 21 Apr 2024 01:09:02 +0000</pubDate>
      <link>https://springbuilders.dev/michael_isvy_13067a826322/why-do-we-need-to-use-autowired-inside-spring-boot-tests-47eb</link>
      <guid>https://springbuilders.dev/michael_isvy_13067a826322/why-do-we-need-to-use-autowired-inside-spring-boot-tests-47eb</guid>
      <description>&lt;p&gt;Starting from Spring 5, we don't need to specify @Autowired inside a Spring bean. &lt;/p&gt;

&lt;p&gt;For instance I can do this and it works just fine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Service&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OwnerService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;OwnerRepository&lt;/span&gt; &lt;span class="n"&gt;ownerRepository&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;OwnerService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OwnerRepository&lt;/span&gt; &lt;span class="n"&gt;ownerRepository&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ownerRepository&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ownerRepository&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, in a Spring Boot test, @Autowired still has to be explicit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@SpringBootTest&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VisitServiceTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;VisitService&lt;/span&gt; &lt;span class="n"&gt;visitService&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Autowired&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;VisitServiceTest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;VisitService&lt;/span&gt; &lt;span class="n"&gt;visitService&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;visitService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;visitService&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anybody understands why Spring Boot Tests are different?&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
