<?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 Victor Osipov on Medium]]></title>
        <description><![CDATA[Stories by Victor Osipov on Medium]]></description>
        <link>https://medium.com/@ofrikit94?source=rss-514d3df92cf1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yqN32tmziCfCOvPhUI8Jdw.jpeg</url>
            <title>Stories by Victor Osipov on Medium</title>
            <link>https://medium.com/@ofrikit94?source=rss-514d3df92cf1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:17:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ofrikit94/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[7 Levels of awesomeness in spock]]></title>
            <link>https://medium.com/@ofrikit94/7-levels-of-awesomeness-in-spock-d7bc6bfbcc7?source=rss-514d3df92cf1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7bc6bfbcc7</guid>
            <category><![CDATA[groovy]]></category>
            <category><![CDATA[spock]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[test-automation]]></category>
            <dc:creator><![CDATA[Victor Osipov]]></dc:creator>
            <pubDate>Sat, 04 Aug 2018 13:16:50 GMT</pubDate>
            <atom:updated>2018-08-04T13:16:50.596Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="http://spockframework.org/">Spock</a> is a <a href="http://groovy-lang.org/">Groovy</a> based awesome testing framework for <a href="https://java.com/en/">Java</a> projects, I’m using in my daily work as Software Developer Engineer in Test. Here are the key parts which I love in Spock with very quick deep dive:</p><h3>Setting up gradle:</h3><pre>compile &#39;org.codehaus.groovy:groovy-all:2.4.+&#39;<br>compile &#39;org.spockframework:spock-core:1.1-groovy-2.4&#39;</pre><h3>Awesome level -1:</h3><p><em>*Test class should always extend Specification class and I personally don’t like it.</em></p><pre>class TestClass extends Specification {}</pre><h3>Awesome level 1:</h3><p><em>*This is just an informational annotation and it doesn’t do anything related to code, it just performs some output when the tests are run in your IDE.</em></p><pre>@Title(&quot;This is awesome Spec&quot;)<br>class AwesomeSpec extends Specification {}</pre><pre>@Narrative(&quot;&quot;&quot;<br>This is awesome Spec<br>with very long name&quot;&quot;&quot;)<br>class AwesomeSpec extends Specification {}</pre><h3>Awesome level 2:</h3><p><em>*You can write test names this way…</em></p><pre>def &quot;test awesome test name&quot;(){}</pre><h3>Awesome level 3:</h3><p><em>*You may exclude some test just by adding a @Ignore on test name or on class as in other frameworks, but make sure you import spock specific annotations because it has another test structure.</em></p><pre>@Ignore<br>def &quot;ignore awesome test name&quot;() {}</pre><pre>@Ignore(&quot;no implemented awesome feature&quot;)<br>def &quot;ignore not implemented awesome feature test&quot;() {}</pre><h3>Awesome level 4:</h3><p><em>*Stepwise makes tests run in specific order(how your write test in test class) and if one of those fails all the following down this chain will be ignored(skip).</em></p><pre>@Stepwise<br>class AwesomeSpecStepwise extends Specification {</pre><pre>    def setupSpec() {<br>        //start service for login<br>    }</pre><pre>    @See(&quot;jira.ticket.url.with.feature.logic&quot;)<br>    def &quot;login in system&quot;(){}</pre><pre>    @Issue(&quot;jira.ticket.number.realted.to.this.bug&quot;)<br>    def &quot;check user info&quot;(){}</pre><pre>    def &quot;a test which assert fail&quot;(){} &lt;--- here test fail</pre><pre>    def &quot;check something else&quot;(){} &lt;--- this will be ignored</pre><pre>    @Timeout(1)<br>    def &quot;very long running test, fail if more than 1 seconds running&quot;(){}</pre><pre>@Timeout(value = 2, unit = TimeUnit.<em>SECONDS</em>)<br>    def &quot;very long running test, fail if more than 2 seconds running&quot;(){}</pre><pre>    def cleanupSpec() {<br>        //stop service for login<br>    }<br>}</pre><h3>Awesome level 5:</h3><p><em>*My favorite part when tests fail </em>:smile:<em> is their absolutely awesome output to check the error:</em></p><p><em>Integer:</em></p><pre><em>Condition not satisfied:<br>A * 2 == B<br>| | | |<br>4 8 | 10<br> false</em></pre><pre><em>Expected :10</em></pre><pre><em>Actual :8</em></pre><p><em>String:</em></p><pre><em>Condition not satisfied:<br>A == B<br>| | |<br>| | cba<br>| false<br>| 2 differences (33% similarity)<br>| (a)b(c)<br>| (c)b(a)<br>abc</em></pre><pre><em>Expected :cba</em></pre><pre><em>Actual :abc</em></pre><p>Custom object with toString() method overrided:</p><pre>Condition not satisfied:</pre><pre>user1 == user2<br>|     |  |<br>|     |  User{id=2, name=&#39;user2&#39;}<br>|     false<br>User{id=1, name=&#39;user1&#39;}</pre><h3>Awesome level 6:</h3><p><em>*Sometimes we have to check if a method throws an exception and check it’s message or something like this related to exception:</em></p><pre>def &quot;throw exception&quot;(){<br>    when:<br>    throw new IllegalAccessException()</pre><pre>    then:<br>    thrown(IllegalAccessException) &lt; --- this will pass<br>}</pre><pre>def &quot;not throw exception&quot;(){<br>    expect:<br>    thrown(IllegalAccessException)<br>}</pre><p>Second test will fail with:</p><pre><em>Expected exception of type ‘java.lang.IllegalAccessException’, but no exception was thrown.</em></pre><h3>Awesome level 7:</h3><p><em>*Here is the key part of doing test, like data source set in testng and @Stepwise will execute all methods which enrolled and if any method inside will fail next tests will be skipped.</em></p><pre>@Stepwise<br>class AwesomeSpec extends Specification {</pre><pre>    @Unroll<br>    def &quot;(table)Check if #A * 2 == #B&quot;() {<br>        expect:<br>        assert A * 2 == B</pre><pre>        where:<br>        A | B<br>        1 | 2<br>        2 | 4<br>        3 | 6<br>        4 | 8<br>    }</pre><pre>    @Unroll<br>    def &quot;(list)Check if #A * 2 == #B&quot;() {<br>        expect:<br>        assert A * 2 == B</pre><pre>        where:<br>        A &lt;&lt; [1,2,3,4]<br>        B &lt;&lt; [2,4,6,8]<br>    }</pre><pre>    @Unroll<br>    def &quot;(query)Login #USER and #PASS&quot;() {<br>        when:<br>        login(USER, PASS)</pre><pre>        then:<br>        assert checkUserInfoAsIsValid()</pre><pre>        where:<br>        [USER, PASS] &lt;&lt; sql.rows(&quot;select USER, PASS from users&quot;)<br>    }</pre><pre>    @Unroll<br>    def &quot;(dataset)Login #USER.name and #USER.pass&quot;() {<br>        when:<br>        //user have defined getName() and getPass() and can be <br>        //accessed in test name also<br>        login(USER.name, USER.pass)</pre><pre>        then:<br>        assert checkUserInfoAsIsValid()</pre><pre>        where:<br>        USER &lt;&lt; getListOfUsers//return List&lt;User&gt;<br>    }<br>}</pre><p><strong><em>These are the key parts which I use on a daily basis and I’m very happy with this awesome framework, I wrote this post because didn’t find similar article. I think most of people don’t read all or big part of the documentation to check if framework fits their needs, but documentation are really cool </em></strong><a href="http://docs.spockframework.org/"><strong><em>check it</em></strong></a><strong><em>.</em></strong></p><p>Bonus:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15cf2905fd046d3942d50782e11cf322/href">https://medium.com/media/15cf2905fd046d3942d50782e11cf322/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*im_QLTht0zddTVPN5y4AjA.png" /><figcaption>Method marked as Unroll will be put by IDEA in the end because it is generated in runtime not at compile time</figcaption></figure><p>Execution is always as you write test for my case is:</p><ul><li>test1</li><li>test2</li><li>all login test</li><li>test4</li></ul><p>PS: This is my first post (and English is my third language, please don’t judge me too harshly) :relaxed: :wink:</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7bc6bfbcc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>