{"id":148,"date":"2024-05-14T13:22:48","date_gmt":"2024-05-14T16:22:48","guid":{"rendered":"https:\/\/springmasteryhub.com\/?p=148"},"modified":"2024-05-14T13:22:48","modified_gmt":"2024-05-14T16:22:48","slug":"specification-based-testing-a-developers-secret-weapont","status":"publish","type":"post","link":"https:\/\/springmasteryhub.com\/?p=148","title":{"rendered":"Specification-Based Testing: A Developer\u2019s Secret Weapont"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>One quick story:<\/strong><\/h3>\n\n\n\n<p>I was adding a new feature that needed an API client created by another developer. The API required three inputs: ID, country code, and phone number. I followed this specification, made a test, and all seemed good. But when I updated my code later before deploying. I found out the other developer had changed the order of the inputs from the client method that I was using. My test caught the mistake before it went to production.<\/p>\n\n\n\n<p>This real story shows one scenario that specification-based test. And how it could save you from creating a new bug in your system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What is Specification-based testing?<\/strong><\/h3>\n\n\n\n<p>Specification-based testing is a black box technique where the developer has to write the tests by following the specification that the code was built. The idea is to use the specification to create test scenarios that will match the defined business rules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why Specification-based testing important?<\/strong><\/h3>\n\n\n\n<p>This technique is important because it helps you to check the proper behavior of the code if the code is following the specification that it was built on. It helps you to identify some misunderstandings to clear out. Also, it helps you to understand the behavior of code that you didn\u2019t write in an exploratory way.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Five Steps to Implement Effective Specification-Based Testing<\/h3>\n\n\n\n<p>1 &#8211;\u00a0<strong><a href=\"https:\/\/springmasteryhub.com\/2024\/05\/15\/specification-based-testing-understand-the-requirements\/\">Understand the requirements<\/a>:<\/strong>\u00a0Understand the business rules that led to the development of the code. Consider the inputs, what they are, how they fit with the business rules,\u00a0what are\u00a0the objectives of each one, and\u00a0what it represents. Do the same thing with the result.<\/p>\n\n\n\n<p>2 &#8211;\u00a0<strong><a href=\"https:\/\/springmasteryhub.com\/2024\/05\/16\/specification-based-testing-explore-the-program\/\">Explore the program<\/a>:<\/strong>\u00a0Test a variety of\u00a0inputs,\u00a0and\u00a0see what results from it.\u00a0This step is\u00a0good\u00a0for understanding code\u00a0that\u00a0you\u00a0didn\u2019t\u00a0write (if you wrote it,\u00a0this step\u00a0is optional).\u00a0It will look like\u00a0that you\u00a0are doing a reverse engineering of the software.<\/p>\n\n\n\n<p>3 &#8211;\u00a0<strong><a href=\"https:\/\/springmasteryhub.com\/2024\/05\/17\/specification-based-testing-exploring-partitions\/\">Explore inputs, outputs, and partitions<\/a>:<\/strong>\u00a0check the parameter\u00a0types,\u00a0and\u00a0how many there are, explore each of them individually (null values, negative values, higher values, lower values, things that could break stuff), then explore them together, check how the inputs affect the results.<\/p>\n\n\n\n<p>4 &#8211;\u00a0<strong><a href=\"https:\/\/springmasteryhub.com\/2024\/05\/20\/specification-based-testing-analyze-boundaries\/\">Analyze boundaries<\/a>:<\/strong>\u00a0check the boundaries of your\u00a0code,\u00a0and\u00a0test passing values\u00a0that are\u00a0on the edge of your validations, which is a common place to have bugs in it. Example: if you have a password validator that checks if the password has\u00a08\u00a0or more characters, do a test with exactly\u00a08\u00a0characters, maybe\u00a0in a\u00a0hurry\u00a0you misplaced a \u2265 to a &gt;\u00a0introducing\u00a0a bug in your code.<\/p>\n\n\n\n<p>5 &#8211;\u00a0<strong><a href=\"https:\/\/springmasteryhub.com\/2024\/05\/21\/specification-based-testing-devise-test-cases\/\">Devise test cases<\/a>:<\/strong>\u00a0After these steps,\u00a0you&#8217;ll\u00a0understand the code.\u00a0You can then create tests based on these results. Some may be redundant\u00a0and\u00a0testing all scenarios may not be beneficial. Choose the most relevant ones for your application. Domain knowledge can help identify unlikely scenarios.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Want to know more about this topic?<\/strong><\/h3>\n\n\n\n<p>In the following days, I\u2019ll dive into each of those steps in more detail, follow me, and do not miss my next blog posts of this series when it comes out.<\/p>\n\n\n\n<p><a href=\"https:\/\/twitter.com\/WillianFMoya\">Willian Moya (@WillianFMoya) \/ X (twitter.com)<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.linkedin.com\/in\/willianmoya\/\">Willian Ferreira Moya | LinkedIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One quick story: I was adding a new feature that needed an API client created by another developer. The API required three inputs: ID, country code, and phone number. I followed this specification, made a test, and all seemed good. But when I updated my code later before deploying. I found out the other developer [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2,4],"tags":[18,20,26,27],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-best-pratices","category-junit","tag-programming","tag-software-development","tag-technology","tag-testing"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=148"}],"version-history":[{"count":0,"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions"}],"wp:attachment":[{"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/springmasteryhub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}