Assertion Roulette doesn’t mean that multiple assertions are bad. When I coach teams or individual developers in test-driven development (TDD) or unit testing, I frequently encounter a particular notion: Multiple assertions are bad. A test must have only one assertion. That idea is rarely helpful. Let’s examine a realistic code example and subsequently try to understand the origins of the notion. Outside-in TDD Consider a REST API that enables you to make and cancel restaurant reservations.
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by Mark Seeman
C#: IEnumerable, yield return, and lazy evaluation
Let’s talk about one of my favorite .NET features: IEnumerable. This interface enables iterating over a collection. In other words, if something is an IEnumerable, you can mostly think of it like an array or a list. You can use a foreach statement to loop through it, you can use LINQ to map or reduce it in a hundred different ways, or you can explicitly cast it to an array with .ToArray() and access elements by index.
Underscoring (or dunder-scoring) the importance of native type methods in Python
All data in Python resides in objects. And all Python objects have a type with associated attributes and methods. Many of the native data types come with their own methods to create and initialize new instances and work with various operators by default. Your custom classes aren’t so lucky. Fortunately, you can ensure that your classes and objects behave like these native data types using something known as dunder methods or magic methods.
Use Git tactically
In the movie Free Solo the rock climber Alex Honnold trains to perform a free solo climb of El Capitan, a mountain in Yosemite. (El Capitan. Photo by Mike Murphy, 2005.) It’s a good movie, but if you haven’t seen it, free solo climbing is when you scale a rock face without ropes, harness, or safety equipment. If you lose your grip and fall, you’ll die. El Capitan, just to rub it in, is 914 meters of vertical rock.
Favor real dependencies for unit testing
If you’ve worked with unit testing, you’ve probably used dependency injection to be able to decouple objects and control their behavior while testing them. You’ve probably injected mocks or stubs into the system under test in order to define repeatable, deterministic unit tests.
Introducing The Key
Good artists copy. Great artists steal. Greatest artists copy, then paste. Simplicity. Elegance. Form. Function. Today marks a new beginning for programmers around the world. Stack Overflow is proud to unveil our first venture into hardware, The Key™. They say good artists copy, but great artists steal. They were wrong. Great artists, developers, and engineers copy. Then they paste.
How to localise engagement during lockdown
Pic: Shutterstock Many organisations with distributed workforces have struggled to keep messaging and communications consistent during a series of lockdowns. Digital platforms can help reach a range of workers, from those in the office to those on furlough or self-isolating, says Mark Seemann. The struggle to establish and maintain a consistent culture and set of behaviours across a workforce is nothing new.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Mark
Contact Mark, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack