Learn Lua With Tests

min read

At 175 words per minute.

2026-05-17 Back to posts

Lua logo

Today I started working on my first book, Learn Lua With Tests

Today I started working on my first book, Learn Lua With Tests

See live updates!

Lua is such a great language. Simple to understand but capable of a lot.

I’ve written about the most popular quirk of Lua before and have been building projects with it instead of Python for over 2 years now.

Many other languages such as C#, Go have excellent resources about TDD in that language. Lua is lacking of a similar resource.

I wanted to create a new way of writing Lua. Since I am opinionated as hell, I also created a unit testing library to go along with the book.

Why write a book about it?

When I first started diving deep into Lua, I noticed a massive gap in the ecosystem. There are plenty of guides that teach you how to write tables or write loops, but almost nothing that teaches you how to write ‘production ready’ Lua from day one.

With the nature of the language, it is often picked up by people with non technical backgrounds. Unit testing may be a bit too difficult for beginners or non-programmers. I have my hopes up, though!

What we are building

Over the course of the book, we will cover:

  • The Foundations of TDD: Understanding the Red-Green-Refactor cycle using Lua’s straightforward syntax.
  • Internals of ‘Check Your Lua’: Check Your Lua is a unit testing framework for Lua made by me. Learn the process of Describe It -> Check It -> Refactor It. I will also cover LuaUnit, the most popular and XUnit-derived library for unit testing in Lua.
  • Testing the Quirks: Mastering tables, metatables, and object-oriented patterns in Lua through strict unit tests.
  • Building Real Tools: Rolling up our sleeves to understand how real software is built.

Stay tuned for updates as I draft the chapters.

The code will be open-sourced on my Github.

Learning Lua through test driven development

  • Explore Lua and different unit testing libraries.
  • Get started with TDD. Lua is excellent for unit testing due to its simplicity.
  • Leave confident that you can build software in Lua with minimal bugs.

That is the core philosophy behind this project. Writing tests shouldn’t be a chore you tack on at the end. It should be the roadmap that guides you.

A sneak peek

Run setup or teardown logic before and after every it block within the current scope.

describe("database suite", function()
  local db
  cyl.before(function() db = connect_db() end)
  cyl.after(function() db:close() end)

  it("queries records", function() expect.exist(db) end)
end)

Skipping Tests

Pass false as the third argument to it() to skip execution temporarily.

it("wip feature", function()
  expect.equal(1, 2)
end, false)

The Red-Green-Refactor loop in Lua feels natural because the language gets out of your way. Write the test, watch it fail, make it pass, clean it up.

What makes Lua different

Lua is not like most languages you have tested in before. A few things to be aware of:

Lua QuirkWhat it means for testing
Tables are everythingYou will write a lot of table assertion helpers
1-based indexingOff-by-one errors are more common than you think
No classes, just metatablesOOP patterns need explicit testing
nil is falsy, false is falsyEasy to write bad assertions without knowing it
Global by defaultlocal discipline is something TDD will force on you

These quirks are not problems. They are just things you need to understand before you can test around them confidently. The book covers all of them.

The testing libraries

There are two libraries covered in the book:

Check Your Lua - my own library. Built around the Describe It -> Check It -> Refactor It pattern. Lightweight and opinionated. If you are starting fresh, this is the one I recommend.

LuaUnit - the most widely used Lua testing library. XUnit-style, battle tested, and you will likely encounter it in existing codebases. Knowing both is worth your time.


I will be posting updates here as the book progresses.

See live updates here.

Nick Stambaugh is a writer, entrepreneur, and enterprise software engineer

Recent Posts

Learn Lua With Tests

Today I started working on my first book, Learn Lua With Tests

2026-05-17

Read more →

#Lua #Coding #Tech

On Brevity

Why using fewer words at the right moment is the ultimate competitive advantage.

2026-05-15

Read more →

#Philosophy #SelfHelp

Selling an html file for a few grand

While the tech around us is constantly evolving, that doesn't mean what is new is always the correct tool for the job.

2026-05-15

Read more →

#Business #Tech

I Don't Follow, I Subscribe

For over 7 years, I have almost never engaged with social media. I'm sharing my story to help those who are addicted to social media or need direction in their careers.

2026-04-09

Read more →

#SelfHelp #SocialMedia

Why I Let GitHub Actions Maintain My GitHub Profile README

How manually updating your GitHub profile README quietly fails at scale, and how I use GitHub Actions to keep it accurate, current, and maintenance-free.

2026-01-06

Read more →

#Automation #DevOps #Engineering

Why Your Astro JavaScript Works in Chrome but Breaks in Firefox

How browser inconsistencies in JavaScript APIs can silently tank your Astro site, and why engineers often miss them.

2025-12-25

Read more →

#WebDev #Astro #Frontend #JavaScript