Have you ever wondered what happens when you run a Minitest test suite? How does it work?

This article will demystify Minitest's magic by going deep into its source code. After reading it, you'll no longer consider Minitest a magical black box and will understand how Minitest discovers your tests methods and executes them.

Although the standard programming wisdom instructs us to avoid it, reinventing the wheel is a great way to learn the basic principles about the wheel.

So how does Minitest work?

Let's write a simplest code possible that demonstrates how it's used:

When we run it, we get the following output:

Let's try to figure out how it works by removing the require line. If we run it without the require , we'll get the following error:

It looks like we're going to need to define that class, so let's do that: