{"id":3377,"date":"2020-02-14T11:28:40","date_gmt":"2020-02-14T10:28:40","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=3377"},"modified":"2021-12-23T14:10:07","modified_gmt":"2021-12-23T13:10:07","slug":"how-to-challenge-your-code-with-property-based-testing-part-3","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/","title":{"rendered":"How to Challenge Your Code with Property-Based Testing \u2013 Part 3"},"content":{"rendered":"\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-a01513c2-a64c-4e0d-9cf6-2fee47310940      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#property-based-testing-quick-recap\" class=\"uagb-toc-link__trigger\">Property-based testing: quick recap<\/a><li class=\"uagb-toc__list\"><a href=\"#realistic-case-scenario-generators\" class=\"uagb-toc-link__trigger\">Realistic Case Scenario &#8211; Generators<\/a><li class=\"uagb-toc__list\"><a href=\"#debugging-a-disproven-property\" class=\"uagb-toc-link__trigger\">Debugging a Disproven Property<\/a><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p>Property-based testing suggests a new way to test software, going beyond the example-based approach and stressing your code with random, realistic inputs. Follow this 3-issue mini serie about property-based testing and Kenny Baas and Jo\u00e3o Rosa speech at Codemotion Rome 2019.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Property-based testing: quick recap<\/h2>\n\n\n\n<p>In this third and last issue about property-based testing (see the <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/backend-dev\/how-to-challenge-your-code-with-property-based-testing-part-1\/\" class=\"ek-link\">first issue here<\/a>, and the <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/backend-dev\/property-based-testing-2\/\" class=\"ek-link\">second one here<\/a>), we\u2019ll see how this approach &#8212; and some interesting features provided by QuickCheck, the reference library for property-based testing &#8212; can help us to set up meaningful and useful tests for our methods and functions. But before going any deeper, a quick summary about what we have learned about property-based testing so far.<\/p>\n\n\n\n<p><strong>Property-based tests are, in short, parameterized tests on steroids<\/strong>, that can feed test methods with a sequence of random inputs. Each test method must be <strong>designed to check and assert the desired behavior<\/strong> (property) from an input, usually within a given range. This approach gives to property-based testing the ability to \u201cexplore\u201d what could happen in previously unforeseen conditions.&nbsp;<\/p>\n\n\n\n<p>So, if we are writing a test to check our super fast method to reverse an array of strings, we should not check that given <code>[\u201ca\u201d, \u201cn\u201d, \u201ck\u201d]<\/code>, the result is <code>[\u201ck\u201d, \u201cn\u201d, \u201ca\u201d]<\/code>, but we could check, for instance,&nbsp; that reversing any random array of string we have a different array and reversing it again we have the same initial one. If or when the test fails, we have found a sequence that breaks our code.<\/p>\n\n\n\n<p>This example introduces us to the main topics of this issue: <strong>how to generate a random input<\/strong> for a non-basic data\/object and <strong>how to reproduce a failing run\/scenario<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Realistic Case Scenario &#8211; Generators<\/h2>\n\n\n\n<p>Let\u2019s do it building code and tests for a realistic scenario: redeeming fidelity points bonus when our customer buys 3 or more special product with a single purchase. How can we check it with property-based testing? How property-based testing can help us to improve our code? Let\u2019s see it.<\/p>\n\n\n\n<p>We can, as a first move, write our checks using a \u201cplain\u201d unit based testing. We have two different cases to check: the first one is when our customer will do a purchase that can redeem fidelity points, the second one is when the purchase can\u2019t redeem points. Our tests can be something like the following:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/ee6b3d4016cfca4082318fc992df6ebc.js\"><\/script>\n\n\n\n<p> Where <code>FidelityPoints<\/code> is our class that will take care of checking if the current purchase can redeem the fidelity points (though the <code>redeemBonus()<\/code> method) and <code>generateCartWithSpecialProductCount()<\/code> is a helper method that will provide a list of Product with the desired count of special products in it.<\/p>\n\n\n\n<p>A simple way to generate such list of products is something like this:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/61a32722a483ef129b02279d1bf62661.js\"><\/script>\n\n\n\n<p>Great! Now we have tests that can actually check the desired behavior, but basically they verify a single list of products &#8212; and, to be honest, a really unrealistic list of products.&nbsp;As we have seen in the previous issue, with property-based testing and QuickCheck we use basic types (int, double, \u2026) as input for our unit tests, specifying the desired range. But QuickCheck also provides the <strong>ability to pass as input any kind of object by defining our own generators<\/strong>. This helps us to write something like:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/27564f9b32ecfbc9381efb84c66652fc.js\"><\/script>\n\n\n\n<p>Moreover we can configure the generators to follow the behaviour we need for our test cases. Of course writing a generator will require some upfront investment, but it will be rewarded by the effectiveness of each test run.An example of a generator for <code>FidelityPoints<\/code> can create a list of products of random length with a random number of special products inside it, with the ability to choose the min and the max number of special items.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/df77cb7f450a2e9e7c6549efe1bb74bd.js\"><\/script>\n\n\n\n<p>The actual implementation requires some code glue, such as the definition of an annotation interface to actually tune the min\/max range at test run. You can see and play with the <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/elleuca\/codemotion-magazine-property-testing-demo\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">code hosted on github<\/a>. Now, every time we run the tests, a new set of inputs generated from a random seed are provided to our checks and\u2026 surprise!&nbsp; Sometimes the <code>earnFidelityPointsIfYouBoughtMoreThan3SpecialProducts()<\/code> test method fails.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Debugging a Disproven Property<\/h2>\n\n\n\n<p>In order to <strong>understand why a test fail happened<\/strong>, we can rely on two features provided by QuickCheck: shrinking and running with seed.<\/p>\n\n\n\n<p>When a property-based test fails, its output provides a message like the following one:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">java.lang.AssertionError: Property named <span class=\"hljs-string\">'checkFailingEarnFidelityScenarioWithSeed'<\/span> failed (\nExpected: is &lt;<span class=\"hljs-literal\">true<\/span>&gt;\n     but: was &lt;<span class=\"hljs-literal\">false<\/span>&gt;)\nWith <span class=\"hljs-built_in\">arguments<\/span>: &#91;me.elleuca.part3.FidelityPoints@<span class=\"hljs-number\">5<\/span>bda8e08]\nSeeds <span class=\"hljs-keyword\">for<\/span> reproduction: &#91;<span class=\"hljs-number\">3260006997795642664<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It means that at least one of the random inputs from the random sequence wasn\u2019t able to prove the property.&nbsp; Running the test again with \u201c<code>shrink<\/code>\u201d mode, will help to find \u201csmaller\u201d sets of input that also disprove the property.&nbsp;<\/p>\n\n\n\n<p>When we have shrunken values, we can use the seed &#8212; i.e. seed for the source of randomness generator &#8212; , to reproduce the same conditions and get the same input values:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/e93dfb6bdbda8d22c82ff1f256c42202.js\"><\/script>\n\n\n\n<p> Please note that the <code>@When<\/code> annotation used to reproduce a dispoven property also can constraint expressions allow us to filter the values that reach a property parameter (for example <code>@When(satisfies = \"#_ &gt;= 0 &amp;&amp; #_ &lt;= 9\") int digit<\/code>)<\/p>\n\n\n\n<p>For more info about property-based testing you can start from the <a href=\"https:\/\/github.com\/elleuca\/codemotion-magazine-property-testing-demo\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">demo project implemented for this article<\/a> and of course any implementation of <a href=\"https:\/\/en.wikipedia.org\/wiki\/QuickCheck\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener nofollow\" class=\"ek-link\">QuickCheck<\/a>.<\/p>\n\n\n\n<p>If you are curious about why unit test in the demo project for <code>redeemBonus()<\/code> method are fine and property-based tests fail, well, the answer is simple. <strong>Unit tests leverage on examples<\/strong> of what we expect to be a valid input (do you remember the specs? \u201cCustomer can redeem fidelity points when she buys 3 or more special product with a single purchase\u201d. But the actual implementation of <code>redeemBonus()<\/code> method checks if the customer buys 3 or more special product with a single purchase of at least 5 products.&nbsp;<\/p>\n\n\n\n<p>As happens in every real project, code (and specs) changes. So make your code more robust with property-based test now \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.<\/p>\n","protected":false},"author":30,"featured_media":3382,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":4,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[9885],"tags":[4,4359],"collections":[],"class_list":{"0":"post-3377","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-qa-testing","8":"tag-codemotion-rome","9":"tag-testing","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Property-based testing: how to challenge your code (part 3) - Codemotion<\/title>\n<meta name=\"description\" content=\"In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Challenge Your Code with Property-Based Testing \u2013 Part 3\" \/>\n<meta property=\"og:description\" content=\"In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-14T10:28:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-23T13:10:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1012\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Luca Ferretti\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Luca Ferretti\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/\"},\"author\":{\"name\":\"Luca Ferretti\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/00344cc4e23bb0758378ab701b57f1a1\"},\"headline\":\"How to Challenge Your Code with Property-Based Testing \u2013 Part 3\",\"datePublished\":\"2020-02-14T10:28:40+00:00\",\"dateModified\":\"2021-12-23T13:10:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/\"},\"wordCount\":975,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg\",\"keywords\":[\"Codemotion Rome\",\"Testing\"],\"articleSection\":[\"QA\/Testing\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/\",\"name\":\"Property-based testing: how to challenge your code (part 3) - Codemotion\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg\",\"datePublished\":\"2020-02-14T10:28:40+00:00\",\"dateModified\":\"2021-12-23T13:10:07+00:00\",\"description\":\"In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg\",\"width\":1012,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Backend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/backend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Challenge Your Code with Property-Based Testing \u2013 Part 3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/00344cc4e23bb0758378ab701b57f1a1\",\"name\":\"Luca Ferretti\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a7c16ad1483e63c6ae25d1370bfab6252a285d959ed68a5e385f98e66f0b420a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a7c16ad1483e63c6ae25d1370bfab6252a285d959ed68a5e385f98e66f0b420a?s=96&d=mm&r=g\",\"caption\":\"Luca Ferretti\"},\"description\":\"Affezionato al caro vecchio C, passato non troppo recentemente alle pi\u00c3\u00b9 arzigogolate frontiere del Web, Luca Ferretti ha da poco scelto il suo motto su Twitter: I break stuff, I build relationships. \u00c3\u02c6 cos\u00c3\u00ac, tra una ispezione del DOM e una apparizione nella stanza accanto per discutere con il team del frontend di un pixel messo storto, tra una traduzione di Ubuntu e un rebuild dei sorgenti di GNOME (rigorosamente di notte), che trascorre le sue giornate nell'incessante ricerca della perfezione ;-)\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/luca-ferretti\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Property-based testing: how to challenge your code (part 3) - Codemotion","description":"In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/","og_locale":"en_US","og_type":"article","og_title":"How to Challenge Your Code with Property-Based Testing \u2013 Part 3","og_description":"In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.","og_url":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2020-02-14T10:28:40+00:00","article_modified_time":"2021-12-23T13:10:07+00:00","og_image":[{"width":1012,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg","type":"image\/jpeg"}],"author":"Luca Ferretti","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Luca Ferretti","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/"},"author":{"name":"Luca Ferretti","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/00344cc4e23bb0758378ab701b57f1a1"},"headline":"How to Challenge Your Code with Property-Based Testing \u2013 Part 3","datePublished":"2020-02-14T10:28:40+00:00","dateModified":"2021-12-23T13:10:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/"},"wordCount":975,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg","keywords":["Codemotion Rome","Testing"],"articleSection":["QA\/Testing"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/","url":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/","name":"Property-based testing: how to challenge your code (part 3) - Codemotion","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg","datePublished":"2020-02-14T10:28:40+00:00","dateModified":"2021-12-23T13:10:07+00:00","description":"In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg","width":1012,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/how-to-challenge-your-code-with-property-based-testing-part-3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Backend","item":"https:\/\/www.codemotion.com\/magazine\/backend\/"},{"@type":"ListItem","position":3,"name":"How to Challenge Your Code with Property-Based Testing \u2013 Part 3"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/00344cc4e23bb0758378ab701b57f1a1","name":"Luca Ferretti","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a7c16ad1483e63c6ae25d1370bfab6252a285d959ed68a5e385f98e66f0b420a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a7c16ad1483e63c6ae25d1370bfab6252a285d959ed68a5e385f98e66f0b420a?s=96&d=mm&r=g","caption":"Luca Ferretti"},"description":"Affezionato al caro vecchio C, passato non troppo recentemente alle pi\u00c3\u00b9 arzigogolate frontiere del Web, Luca Ferretti ha da poco scelto il suo motto su Twitter: I break stuff, I build relationships. \u00c3\u02c6 cos\u00c3\u00ac, tra una ispezione del DOM e una apparizione nella stanza accanto per discutere con il team del frontend di un pixel messo storto, tra una traduzione di Ubuntu e un rebuild dei sorgenti di GNOME (rigorosamente di notte), che trascorre le sue giornate nell'incessante ricerca della perfezione ;-)","url":"https:\/\/www.codemotion.com\/magazine\/author\/luca-ferretti\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-600x600.jpg","author_info":{"display_name":"Luca Ferretti","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/luca-ferretti\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg",1012,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-768x512.jpg",768,512,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg",1012,675,false],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg",1012,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg",1012,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled.jpg",100,67,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/TestingCup-Polish-Championship-in-Software-Testing-Katowice-2016-scaled-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Luca Ferretti","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/luca-ferretti\/"},"uagb_comment_info":0,"uagb_excerpt":"In this last issue about property-based testing, we\u2019ll see how to implement this approach thanks to the QuickCheck library.","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=3377"}],"version-history":[{"count":4,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3377\/revisions"}],"predecessor-version":[{"id":3611,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3377\/revisions\/3611"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/3382"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=3377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=3377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=3377"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=3377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}