Code Smell 91 - Test Asserts without Description

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.
Search for a command to run...

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.
No comments yet. Be the first to comment.
In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.
Approve the logic once, then let it run the same way forever.

Different stages need different brains.

One Second Brain doesn't scale past one skull.

Style errors double when nobody enforces them.

Know who speaks before the skill runs TL;DR: Always define a clear role at the top of every skill file so you know whose perspective drives the execution. Common Mistake ❌ You write a skill full of

We are big fans of xUnit. But we don't care much for the programmers.
TL;DR: Use asserts with declarative descriptions.
Readability
Hard debugging
Time waste
Put a nice descriptive assertion
Share guides for problem-solving
<?
public function testNoNewStarsAppeared(): void
{
$expectedStars = $this->historicStarsOnFrame();
$observedStars = $this->starsFromObservation();
//These sentences get a very large collection
$this->assertEquals($expectedStars, $observedStars);
//If something fails we will have a very hard debugging time
}
<?
public function testNoNewStarsAppeared(): void
{
$expectedStars = $this->historicStarsOnFrame();
$observedStars = $this->starsFromObservation();
//These sentences get a very large collection
$newStars = array_diff($expectedStars, $observedStars);
$this->assertEquals($expectedStars, $observedStars ,
'There are new stars ' . print_r($newStars,true));
//Now we can see EXACTLY why the assertion failed with a clear and
//Declarative Message
}
Since assert and assertDescription are different functions, we can adjust our policies to favour the latter.
Be respectful to the reader of your assertions.
It might even be yourself!
Photo by Startaê Team on Unsplash
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
John Woods
This article is part of the CodeSmell Series.