<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Maria Michou on Medium]]></title>
        <description><![CDATA[Stories by Maria Michou on Medium]]></description>
        <link>https://medium.com/@maria.michou?source=rss-92e08804b355------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NHgbj255kC-yG63dQlvgzA.png</url>
            <title>Stories by Maria Michou on Medium</title>
            <link>https://medium.com/@maria.michou?source=rss-92e08804b355------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 00:31:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maria.michou/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data driven testing with Spock and JUnit5: Who wins?]]></title>
            <link>https://medium.com/@maria.michou/data-driven-testing-with-spock-and-junit5-who-wins-3fd50d7cb431?source=rss-92e08804b355------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fd50d7cb431</guid>
            <category><![CDATA[spock]]></category>
            <category><![CDATA[parameterized-tests]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[data-driven-testing]]></category>
            <dc:creator><![CDATA[Maria Michou]]></dc:creator>
            <pubDate>Mon, 02 Sep 2019 19:46:00 GMT</pubDate>
            <atom:updated>2019-09-02T19:46:00.188Z</atom:updated>
            <content:encoded><![CDATA[<p>Is writing parameterized tests an easy task in JUnit? How does it compare to Spock?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KKdpP9yxK0VWkTte0lEUMw.jpeg" /><figcaption>Photo: trainer24/pixabay</figcaption></figure><p>I’d been a Java developer for some years when in my previous company we started using Groovy and a testing framework “that makes things easier to test” as my more experienced peers used to tell me. If you’re familiar with Groovy, then you know what the advantages are in terms of streams, lists, maps, closures, getters/setters out of the box via reflection (there goes privacy), etc. Some companies will use Groovy for their main development and tests or other will use it only for the latter, in terms of setting up easily test methods, helper functions, no builders needed, etc. Like you’d do with Kotlin.</p><p>Though this article is not here to discuss whether Groovy wins or loses as compared to Java, the former can be combined as the language means to a very powerful testing framework (and my favourite one), Spock. For an introduction and how you can use it, please visit the official <a href="http://spockframework.org/spock/docs/1.0/spock_primer.html">documentation page</a> and an <a href="https://www.baeldung.com/groovy-spock">Introduction to Testing with Spock and Groovy</a>.</p><p>When I started to write tests in Spock, I was amazed with how easy it is to set up and write a paramerized test, i.e. one test or one template if you will, where you specify varying inputs in a multiline block. E.g.</p><pre>import spock.lang.Specification<br>import spock.lang.Unroll</pre><pre>class MathTest extends Specification {</pre><pre>  @Unroll<br>  def &quot;sum of #a and #b equals #expectedResult&quot;() {<br>    <br>    when:<br>    def actualResult = a + b</pre><pre>    then:<br>    expectedResult == actualResult</pre><pre>    where:<br>    a | b | expectedResult<br>    0 | 0 | 0<br>    0 | 1 | 1<br>    1 | 2 | 3<br>  }</pre><pre>}</pre><p>For more information, please visit <a href="http://spockframework.org/spock/docs/1.0/data_driven_testing.html">Data Driven Testing</a> section of Spock documentation.</p><p>In <em>Junit5</em>, you can do the same, albeit not that easily. Let’s see how it goes:</p><p>You replace <em>@Test</em>, with <em>@ParameterizedTest</em>. This annotation is a successor of <em>Junit4</em> annotation: <em>@RunWith(Parameterized.class)</em></p><pre>class MathTest {</pre><pre>  @ParameterizedTest<br>  @CsvFileSource(resources = &quot;numbers.csv&quot;, numLinesToSkip = 1)<br>  void testsForSum(int a, int b, int expectedResult) {<br>    assertEquals(expectedResult, Math.addExact(a, b));<br>  }</pre><pre>}</pre><p><strong>OR:</strong></p><pre>class MathTest {</pre><pre>  @ParameterizedTest<br>  @MethodSource(&quot;populateIntegers&quot;)<br>  void testsForSum_2(int a, int b, int expectedResult) {<br>    assertEquals(expectedResult, Math.addExact(a, b));<br>  }</pre><pre>  private static Stream&lt;Arguments&gt; populateIntegers() {<br>    return Stream.of(<br>      Arguments.of(0, 0, 0),<br>      Arguments.of(0, 1, 1),<br>      Arguments.of(1, 2, 3));<br>  }</pre><pre>}</pre><p>where <em>numbers.csv</em> is:</p><pre>a,b,expected<br>0,0,0<br>0,1,1<br>1,2,3</pre><p>For more info, please visit a comprehensive <a href="https://www.baeldung.com/parameterized-tests-junit-5">Guide to JUnit 5 Parameterized Tests</a> and <a href="https://www.baeldung.com/junit-5-gradle">Using JUnit 5 with Gradle</a>.</p><p>In terms of lines or difficulty, JUnit5 seems to be really intuitive (if you get the gist of naming and basic building blocks for parameterised tests).</p><p>The complexity is increased when we want to test more complicated varying use cases.</p><p>In Spock, the “where” block is easier to construct. It can even take methods as parameters as long as they’re static.</p><p><a href="https://bmuschko.com/blog/junit5-vs-spock-showdown/">JUnit 5 vs. Spock feature showdown</a> offers a more exhaustive comparison.</p><p>Finally, please visit <a href="https://github.com/mariamichou/playground">playground</a> and <a href="https://github.com/mariamichou/playground-junit">playground-junit</a> GitHub repositories that investigate the same use case scenario, using <em>Groovy/Spock</em> and <em>Java/JUnit5 </em>respectively. Both repos have the same <a href="https://github.com/mariamichou/playground/blob/master/src/main/java/com/example/playground/colours/Colour.java">Colour</a><em> </em>class<em>, playground</em> one has a <em>Groovy/Spock</em> based <a href="https://github.com/mariamichou/playground/blob/master/src/test/groovy/com/example/playground/colours/ColourTest.groovy">ColourTest</a><em> </em>class, while playground-junit has a <em>Java/JUnit5</em> based <a href="https://github.com/mariamichou/playground-junit/blob/master/src/test/java/com/example/playground/colours/ColourTest.java">ColourTest</a> class. They follow almost identical test cases in order to be able to show and compare the logical flow and different syntax when writing data driven tests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fd50d7cb431" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing beautiful code]]></title>
            <link>https://medium.com/@maria.michou/https-medium-com-maria-michou-writing-beautiful-code-ab331afef54c?source=rss-92e08804b355------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab331afef54c</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Maria Michou]]></dc:creator>
            <pubDate>Sat, 26 Jan 2019 17:11:53 GMT</pubDate>
            <atom:updated>2019-01-26T17:11:53.839Z</atom:updated>
            <content:encoded><![CDATA[<h4>What the heck does beautiful code mean? Does it exist in the backend realm?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LRI_7XL7A_qqDI6oX4kS8w.png" /><figcaption>Photo edited by <a href="https://medium.com/@nsimeonidou">nsimeonidou</a></figcaption></figure><p><em>Disclaimer:</em> the author of this post is a biased, opinionated backend developer. There are a lot of articles/books about best practices, coding guidelines, which I’m sure the majority of us have read and followed. The following is not about that.</p><p>There’s always a battle between frontend (FE) and backend (BE) developers about the latter writing ugly code, because no one will be able to read it, much less understand it but them (and let’s be honest, sometimes, after a few months the ones who wrote the code will want to refactor it, but that’s life).</p><p>I cannot stress enough how strongly I disagree with this opinion. If you break down what FE/UI devs need from their BE counterparts, is actually a payload. Yes, it all boils down to an object (no matter the language) which they take, they restructure it according to the feature’s needs and then, voilà, they deliver it beautifully (if they’re lucky with the help of a good UX designer and CSS) on the screen.</p><p>However, I’ve seen ugly and equally beautiful code in the BE realm. But what is <em>beautiful code</em>?</p><blockquote>Is it having the knowledge and the ability to use the latest coolest features of language “A”? Is it implementing the best design patterns fitting problem ‘X’? Is it (re)structuring the codebase in components/modules according to architecture ‘Z’? Is it adding comments? Is it writing (unit) tests for your functions (methods) in order for your peers (and your future self) to understand what the heck you’ve done? Is it writing readable code, often to the expense of not using cool programming tricks that may reduce lines in your code? Or is it about efficient code? And what about a legacy codebase? How can you write beautiful code, being technologically handicapped and unable to use the latest frameworks and new language features?</blockquote><p>There isn’t only one answer. On the contrary, the answer is all of the above. And of course, it depends on one’s experience, comfort zone or even understanding their peers’ way of coding.</p><p>Although I believe efficiency is a very important aspect that drive us devs to write beautiful code, there is no way you implement one feature, writing what you think is beautiful code, if your peers cannot understand it. When someone first looks at your code, they want to see something self explanatory (from the method/class/package name), then delve into the backbone of the logic and understand it quickly, intuitively first and then in depth. It’s like reading a good book, page by page, in order, without turning them back and forth. The same with the code. Going from point A to point B to point Z, this has to have a meaning, a natural flow. If there are some unit tests, even better. Not only do they help strengthening your code in terms of bugs, but they also explain the logic behind the implementation of the feature and guiding you how to <em>read</em> the code, how to test it, how to debug it, etc.</p><p>Knowing the latest trends and cool features of the language helps, in terms of efficiency, clean code, but it’s not a <a href="https://en.oxforddictionaries.com/definition/panacea">panacea</a>. Most of the times, the new way of doing things is the best way to go, but as with all new things, you have to really know how to use them and what purpose they really serve.</p><p>To recap, beautiful code is not about pretty code. It’s about understanding the purpose each and every bit your codebase serves. Finally, as with UX designers who care about user experience, I really believe that backend developers should care about developer experience, by being thoughtful to their peers and writing code that they themselves can understand and improve it or let others do that, when there’s a need.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab331afef54c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>