Blog
  • devcrisis
  • 🔮Software atoms
    • Validating code Architecture with dependency cruiser
    • Actionable ways to use ChatGPT
    • Most courses aren't worth it
    • SQLite is❤️
    • Stabilizing Tests without fixing them
    • Interviews should copy Advent of Code
    • Rust is nice
    • Agile fatigue is rising
    • Documentation is needed after all
    • The Direction of the JS ecosystem is good
    • Zero configuration == <3
    • Make small pull requests
    • Good practices fade out
    • Rushing !== unmaintainable
    • Commit message readability
    • Universal Practices
    • More functions == good
    • Mocking Private Functionality
    • Lines of code != feature count
    • Different Software - Different Quality
    • junior2mid
    • Book alternatives
    • Courses
    • Type Driven Development
    • Latest and Greatest
    • Real Developers
    • 10x Developer
    • Books for beginners 1
    • Parkinson's Law
    • nest-cli architecture is nice
    • Incremental Feature Delivery
    • Self Healing Software
      • Typed Configuration
  • 💡Memos
    • 2022 Holiday code report
    • Complexity
    • Software Development Fundamentals
  • 🧱foundation
    • Junior2Mid
    • Books and resources for new developers
    • 🏔️Now
Powered by GitBook
On this page
  1. Software atoms

Mocking Private Functionality

😱 Mocking private functionality is bad design! Or is it ?

There are two schools of thought:

  1. Private things should be mocked out - you are interested in testing a unit and must mock out everything

  2. If you need to mock out something private this showcases bad design, therefore you need to refactor

🤔 It depends. On how you scope your private code.

⭐ Generally I am more and more against having lots of private functionality in classes. ⭐ Classes should be so small that no functionality that does something substantial should exist.

! If it exists it must be extracted into it's own class (or function or any container, really)

The extracted class should be scoped in a way that from the architecture perspective it will be usable only by the intended class.

🥰 With this setup you can test. 🥰 You have separated the concerns. 🥰 Have a more decoupled codebase.

But, that is just one way to do it. Strong arguments can be made against. Aren't you polluting the namespace with "fake" classes that shouldn't exist ?

Depends on scoping.

PreviousMore functions == goodNextLines of code != feature count

Last updated 2 years ago

🔮