June 3, 2024, 12:37 p.m. | Maxi Contieri

DEV Community dev.to

You assert that something happened, but why?


TL;DR: Be explicit when creating tests to ensure clarity and maintainability






Problems


  • Readability


  • Coupling to external databases, global state or singletons, static methods or external services


  • Maintenance Difficulty


  • Debugging Complexity


  • Hidden Dependencies






Solutions


  1. Be Explicit


  2. Inline the setup


  3. Use dependency Injection


  4. Use mocking with caution






Context

Your test depends on external data or configurations not immediately visible within the test itself.


This obscures the test’s setup, making it difficult for someone reading …

beginners clarity code complexity context databases debugging dependencies dependency explicit external global hidden injection maintenance problems programming services setup solutions state static tests tutorial webdev

Head of IT Governance IT Risk IT Outsourcing

@ State Street | Munich, Germany

Information Assurance Engineer (Engineer Info Assurance 3) 19608

@ HII | Annapolis Junction, MD, Maryland, United States

VP control design and Development

@ State Street | Dublin 2, Ireland

Channel & Alliances Solution Architect

@ Trend Micro | US Off-Site

Senior DevOps Engineer (f/m/d)

@ E.ON | Essen, DE

DevOps Engineer with OpenShift & Kubernetes

@ Peraton | Arlington, VA, United States