0Pricing
Lua Academy · Lesson

Assertions

Express expected behavior.

What Assertions Do

An assertion is the heart of a test. It states a fact that must be true. If it is, the test continues. If not, busted records a failure with a helpful message.

busted uses the luassert library, accessed through the global assert table.

assert.are.equal(4, 2 + 2)

are.equal

assert.are.equal checks equality with the == operator. The first argument is the expected value, the second is the actual value.

This works for numbers, strings, and booleans, but for tables it compares identity, not contents.

assert.are.equal("hello", greet())
assert.are.equal(10, count)

All lessons in this course

  1. Why Test
  2. describe and it Blocks
  3. Assertions
  4. Mocks and Spies
← Back to Lua Academy