← Lua Academy

Test-driven development · 40 / 69

Test the boundary first

YOUR TASK

Make this happen

3 steps
  1. Write a test that exposes the faulty free-shipping boundary. Then repair the implementation. Your tests will also run against a correct implementation and a deliberately broken one; an always-passing test is not enough.

  2. Write a test in lesson.test.lua, then choose Check solution to record a failing test before changing the implementation.

  3. Repair subject.lua and check again. Your tests must pass and catch the supplied defects. Then refactor.

Read the starter and tests

subject.lua

exports.shipping = function(total: number): number
  if total > 100 then
    return 0
  end
  return 5
end

lesson.test.lua

local t = require("test")
local subject = require("cococo.subject")

-- Write a test that reveals the defect before editing subject.lua.