0Pricing
Lua Academy · Lesson

describe and it Blocks

Structure a test suite.

Structure of a Spec

busted organizes tests with two core functions: describe and it. A describe block groups related tests, and each it block is a single test case.

This structure comes from behavior driven development and reads like plain English.

describe("Stack", function()
  it("starts empty", function()
    assert.are.equal(0, Stack.new():size())
  end)
end)

The describe Block

describe takes a name string and a function. The name should identify the unit or feature being tested, such as a module or class.

Everything inside the function belongs to that group. The name appears in the test output to organize results.

describe("calculator", function()
  -- tests live here
end)

All lessons in this course

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