Mocking is a Code Smell - Deepstash
Introduction to Web 3.0

Learn more about technologyandthefuture with this collection

The differences between Web 2.0 and Web 3.0

The future of the internet

Understanding the potential of Web 3.0

Introduction to Web 3.0

Discover 36 similar ideas in

It takes just

6 mins to read

TDD should lead to better design

TDD should lead to better design

TDD should simplify code, not make it more complicated. If your code becomes harder to read or maintain when you make it testable, you're doing TDD wrong.

You can learn two things:

  • You can write decoupled code without dependency injection, and
  • Maximising code coverage results in diminishing returns.

More complex code often means more cluttered code. Cluttered code is a convenient place for bugs to hide. It's also easier to find things when there's less clutter.

3

1 read

Code smell

A code smell is a surface indication that points to a deeper problem in the system.

Different types of code need different levels (and different kinds) of mocks. Some code exists primarily to facilitate I/O, in which case, there is little to do other than test I/O. Reducing mocks might mean your unit test coverage would be close to 0.

3

0 reads

What is a unit test?

Unit tests test individual units (modules, functions, classes) in isolation from the rest of the program.

  • Generally, units are tested using the public interface of the unit, known as black-box testing. It leads to less brittle tests.
  • In white box testing - where tests are aware of implementation details - any change to the implementation details could break the test, even if the public API continues to function as expected.

3

0 reads

What is test coverage?

Code coverage is the amount of code covered by a test. Increasing coverage beyond 90% seems to have little continued correlation with lower bug density.

There are two kinds of coverage: 

  • Code coverage: how much of the code is exercised, and 
  • Case coverage: how many of the use-case scenarios are covered by the test suites.  

Coverage reports identify code-coverage weaknesses, not case coverages weaknesses.

3

0 reads

Tight coupling

Less coupling makes code easier to extend and maintain. Tight coupling makes code more rigid and brittle and more likely to break when changes are needed.

Coupling takes different forms: 

  • Subclass coupling is dependent on the implementation and hierarchy of the parent class.
  • Control dependencies. Code that tells its dependences what to do. If the control API of the dependency changes, the dependent code will break.
  • State shape dependencies. Code that only uses a subset of the data structure.
  • Event/message coupling. Code that communicates with other units via message passing, events, etc.

3

0 reads

Causes of tight coupling

Tight coupling has many causes: 

  • Mutation vs immutability  
  • Side-Effects vs purity/isolated side-effects  
  • Responsibility overload vs Do One Thing (DOT)  
  • Procedural instructions vs describing structure  
  • Class Inheritance vs composition  

Imperative and object-oriented code is more vulnerable to tight coupling than functional code.

3

0 reads

Composition and mocking

All software development is about the process of breaking a big problem down into smaller independent parts, combining the solutions to form an application that solves the big problem. 

Mocking is necessary when the decomposition strategy failed. When decomposition succeeds, a generic composition utility can be used to compose the pieces together.

3

0 reads

IDEAS CURATED BY

jopineda

Illustrator

Other curated ideas on this topic:

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

100+ Learning Journeys

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving

Unlimited history

Unlimited listening to ideas

Downloading & offline access

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates