{"id":3331,"date":"2020-02-12T11:57:49","date_gmt":"2020-02-12T10:57:49","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=3331"},"modified":"2021-12-23T14:10:23","modified_gmt":"2021-12-23T13:10:23","slug":"property-based-testing-2","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/","title":{"rendered":"How to Challenge Your Code with Property-Based Testing \u2013 Part 2"},"content":{"rendered":"\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-e2102404-e822-4b99-a8fa-e65f481c2068      \"\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=\"#introduction-to-property-based-testing\" class=\"uagb-toc-link__trigger\">Introduction to property-based testing<\/a><li class=\"uagb-toc__list\"><a href=\"#implementing-tests\" class=\"uagb-toc-link__trigger\">Implementing Tests<\/a><li class=\"uagb-toc__list\"><a href=\"#code-as-your-domain-speaks\" class=\"uagb-toc-link__trigger\">Code as Your Domain Speaks<\/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 <span id=\"urn:enhancement-6975e18d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/property\">property<\/span>-based testing and Kenny Baas and Jo\u00e3o Rosa speech at Codemotion Rome 2019.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to property-based testing<\/h2>\n\n\n\n<p>In 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\">previous issue of this mini-series about property-based testing<\/a>, we introduced some basic ideas from which <strong><span id=\"urn:enhancement-4946e972\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/property\">property<\/span>-based testing<\/strong> is derived. To sum up, <span id=\"urn:enhancement-b2e963c7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/property\">property<\/span>-based testing introduces a degree of fuzziness in test inputs, allowing to spot cases when the <span id=\"urn:enhancement-a315408b\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/system\">system<\/span> under test behaves in unexpected way.<\/p>\n\n\n\n<p>Let&#8217;s see a trivial but concrete case, showing how to convert check for a simple <span id=\"urn:enhancement-f27bffe5\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> from unit testing style to a <span id=\"urn:enhancement-868e2aca\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/property\">property<\/span>-based approach. Following example will use <span id=\"urn:enhancement-d27a3378\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/java_programming_language\">Java language<\/span> (and <span id=\"urn:enhancement-7a2d2807\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/junit\">JUnit<\/span> testing framework) and <span id=\"urn:enhancement-7d09c889\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/quickcheck\">QuickCheck<\/span> implementation for <span id=\"urn:enhancement-3ef6cb55\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/java\">Java<\/span>\/<span id=\"urn:enhancement-8c06abbf\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/junit\">Junit<\/span>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementing Tests<\/h2>\n\n\n\n<p>Our mission is to write and verify a <span id=\"urn:enhancement-3d48676e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> that checks if a discount can be applied. A really naive <span id=\"urn:enhancement-56d2fdd5\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/implementation\">implementation<\/span> of such <span id=\"urn:enhancement-b4cffdb6\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> and related <span id=\"urn:enhancement-495b509e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/test_assessment\">tests<\/span> can be something like the following one:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/639e0fe5438012ef6ec1ef6fe813ba02.js\"><\/script>\n\n\n\n<p>Everytime we run those unit <span id=\"urn:enhancement-89ddf43e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/test_assessment\">tests<\/span>, we&#8217;ll repeat the same two checks again and again and again. Moreover, we are checking how our <span id=\"urn:enhancement-4fe2e468\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> is behaving using two values with no meaning or reason. <\/p>\n\n\n\n<p>First step is <strong>write a rationally meaningful check<\/strong>. For example, using&nbsp; common testing techniques such as boundary-value analysis and equivalence partitioning we can choose a set of relevant values to test. At the same time, we can use some features provided by testing framework to parametrize our test run and avoid to have one separate test <span id=\"urn:enhancement-bd2fe949\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> for each chosen value.<\/p>\n\n\n\n<p>So we can <span id=\"urn:enhancement-22853818\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/rewrite_programming\">rewrite<\/span> our <span id=\"urn:enhancement-ba070f23\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/test_assessment\">tests<\/span> in the following way:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/2f3da754733201ce8e63e7d1942ceb2f.js\"><\/script>\n\n\n\n<p>Great! It&#8217;s a step forward, but it still lacks two valuable features of the kind of testing we are aiming for. First, our <span id=\"urn:enhancement-cba3da83\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/test_assessment\">tests<\/span> are still performed against some pre-chosen and fixed value on every execution. Second, our <span id=\"urn:enhancement-dc783b0f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/test_assessment\">tests<\/span> output will we a sequence of true and false, with no particular legibility or meaningfulness about the actual behavior.<\/p>\n\n\n\n<p>Let&#8217;s try to <span id=\"urn:enhancement-fb962b0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/rewrite_programming\">rewrite<\/span> those checks using a <span id=\"urn:enhancement-760a2d2a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/property\">property<\/span>-based framework such as <span id=\"urn:enhancement-34c13d6f\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/quickcheck\">QuickCheck<\/span> and its runner for <span id=\"urn:enhancement-e4250025\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/junit\">JUnit<\/span>:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/elleuca\/f6238b9de0bec2d50d8a78fb02174c43.js\"><\/script>\n\n\n\n<p><span id=\"urn:enhancement-567b97bf\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/junit\">JUnit<\/span> <span id=\"urn:enhancement-c148595a\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/quickcheck\">QuickCheck<\/span> syntax should be simple to understand: basically, we are asking to perform 500 trials (i.e. runs) of each test <span id=\"urn:enhancement-542c2309\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span>, providing each time a different value randomly chosen from the given ranges.<\/p>\n\n\n\n<p>Starting from a trivial unit test, we have built a <span id=\"urn:enhancement-285c8d3e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/inheritance_object-oriented_programming\">super<\/span> test that will able to warn us if out code is doing an undesired behavior when feeded with an unexpected input.<\/p>\n\n\n\n<p>When this happens, <span id=\"urn:enhancement-e549d545\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/quickcheck\">QuickCheck<\/span> provides info about the faulty input and a seed to reproduce it and <span id=\"urn:enhancement-8d3faf09\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/debugging\">debug<\/span> it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code as Your Domain Speaks<\/h2>\n\n\n\n<p>To be honest, the actual benefit of the example provided so far is a little deceptive.<\/p>\n\n\n\n<p>Of course, it is useful to show how to move from unit testing to <span id=\"urn:enhancement-ff739e70\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/property\">property<\/span>-based testing, but it lacks some prominent traits from a production code perspective.<\/p>\n\n\n\n<p>In fact, In order to isolate the <em>DiscountService<\/em> <span id=\"urn:enhancement-cfba5877\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/class_computer_programming\">class<\/span> and simplify our test code, we deliberately took no account for any other object in the domain that could interact with our discount check. In a real world scenario, the price we check against could be the sum of prices of different items in your basket, and maybe in your <span id=\"urn:enhancement-e50243a1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/business_logic\">business logic<\/span> you have to exclude some items from discount calculation.<\/p>\n\n\n\n<p>Moreover, we used the <span id=\"urn:enhancement-e1a1276b\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/java\">Java<\/span> <em>double<\/em> type to represent money and we set a test range up to 49.99. This means that, for example, 49.991 can be a valid input for our <span id=\"urn:enhancement-b29f56e7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span>, but it will never occur as test input (if you consider, for example, fuel prices per liter in Europe, 49.991 can be a valid price that must be rounded).<\/p>\n\n\n\n<p>In the next issue we&#8217;ll see how <span id=\"urn:enhancement-75ea943e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/property\">property<\/span>-based testing can use generators feature from <span id=\"urn:enhancement-7b255d19\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/quickcheck\">QuickCheck<\/span> library to create <span id=\"urn:enhancement-da1f98a0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/randomness\">random<\/span> input for our own <span id=\"urn:enhancement-9e70e82f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/data\">data<\/span> types and domain\/business logics.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<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. Introduction to property-based testing In the previous issue of this mini-series about property-based testing,&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/\">Read more<\/a><\/p>\n","protected":false},"author":30,"featured_media":3332,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_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,52],"collections":[],"class_list":{"0":"post-3331","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-java","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 - Codemotion<\/title>\n<meta name=\"description\" content=\"Property-based testing suggests a new way to test software, going beyond the example-based approach and stressing your code with random, realistic inputs\" \/>\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\/property-based-testing-2\/\" \/>\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 2\" \/>\n<meta property=\"og:description\" content=\"Property-based testing suggests a new way to test software, going beyond the example-based approach and stressing your code with random, realistic inputs\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/\" \/>\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-12T10:57:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-23T13:10:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1002\" \/>\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=\"3 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\/property-based-testing-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/\"},\"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 2\",\"datePublished\":\"2020-02-12T10:57:49+00:00\",\"dateModified\":\"2021-12-23T13:10:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/\"},\"wordCount\":664,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg\",\"keywords\":[\"Codemotion Rome\",\"Java\"],\"articleSection\":[\"QA\/Testing\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/\",\"name\":\"Property-Based Testing: How to Challenge Your Code - Codemotion\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg\",\"datePublished\":\"2020-02-12T10:57:49+00:00\",\"dateModified\":\"2021-12-23T13:10:23+00:00\",\"description\":\"Property-based testing suggests a new way to test software, going beyond the example-based approach and stressing your code with random, realistic inputs\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg\",\"width\":1002,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#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 2\"}]},{\"@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 - Codemotion","description":"Property-based testing suggests a new way to test software, going beyond the example-based approach and stressing your code with random, realistic inputs","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\/property-based-testing-2\/","og_locale":"en_US","og_type":"article","og_title":"How to Challenge Your Code with Property-Based Testing \u2013 Part 2","og_description":"Property-based testing suggests a new way to test software, going beyond the example-based approach and stressing your code with random, realistic inputs","og_url":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2020-02-12T10:57:49+00:00","article_modified_time":"2021-12-23T13:10:23+00:00","og_image":[{"width":1002,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/"},"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 2","datePublished":"2020-02-12T10:57:49+00:00","dateModified":"2021-12-23T13:10:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/"},"wordCount":664,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg","keywords":["Codemotion Rome","Java"],"articleSection":["QA\/Testing"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/","url":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/","name":"Property-Based Testing: How to Challenge Your Code - Codemotion","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg","datePublished":"2020-02-12T10:57:49+00:00","dateModified":"2021-12-23T13:10:23+00:00","description":"Property-based testing suggests a new way to test software, going beyond the example-based approach and stressing your code with random, realistic inputs","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg","width":1002,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/devops\/qa-testing\/property-based-testing-2\/#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 2"}]},{"@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\/190404-F-AU274-002-scaled-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-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\/190404-F-AU274-002-scaled.jpg",1002,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled-300x202.jpg",300,202,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled-768x517.jpg",768,517,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg",1002,675,false],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg",1002,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg",1002,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled.jpg",100,67,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-scaled-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/02\/190404-F-AU274-002-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":"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. Introduction to property-based testing In the previous issue of this mini-series about property-based testing,&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3331","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=3331"}],"version-history":[{"count":4,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3331\/revisions"}],"predecessor-version":[{"id":3613,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/3331\/revisions\/3613"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/3332"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=3331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=3331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=3331"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=3331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}