All Projects → IUdalov → u-test

IUdalov / u-test

Licence: MIT License
Sane and simple unit testing framework for Lua

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to u-test

lua-leveldb
Lua bindings for google's leveldb library.
Stars: ✭ 50 (-16.67%)
Mutual labels:  luarocks
estj
EstJ is my own test framework!
Stars: ✭ 13 (-78.33%)
Mutual labels:  test-framework
specdris
A test framework for Idris
Stars: ✭ 55 (-8.33%)
Mutual labels:  test-framework
beJS
Simple, light-weight assertions framework for javascript
Stars: ✭ 12 (-80%)
Mutual labels:  test-framework
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-66.67%)
Mutual labels:  test-framework
MAQS
Magenic's automation quick start
Stars: ✭ 46 (-23.33%)
Mutual labels:  test-framework
cassowary.lua
A Lua port of the cassowary constraint solver engine
Stars: ✭ 34 (-43.33%)
Mutual labels:  luarocks
bdd-for-c
A simple BDD library for the C language
Stars: ✭ 90 (+50%)
Mutual labels:  test-framework
behave
Demoiselle Behave
Stars: ✭ 30 (-50%)
Mutual labels:  test-framework
TcUnit-Runner
Program that makes it possible to automate runs of TcUnit unit tests
Stars: ✭ 23 (-61.67%)
Mutual labels:  test-framework
xtd
Free open-source modern C++17 / C++20 framework to create console, forms (GUI like WinForms) and unit test applications on Microsoft Windows, Apple macOS and Linux.
Stars: ✭ 321 (+435%)
Mutual labels:  test-framework
lua-lpugl
A minimal Lua-API for building GUIs using Cairo or OpenGL (see: https://github.com/osch/lua-lpugl#lpugl)
Stars: ✭ 19 (-68.33%)
Mutual labels:  lua-library
page-content-tester
Paco is a Java based framework for non-blocking and highly parallelized Dom testing.
Stars: ✭ 13 (-78.33%)
Mutual labels:  test-framework
tester
Lightweight test utilities to use with Go's testing package
Stars: ✭ 43 (-28.33%)
Mutual labels:  test-framework
PICO-EC
A tiny scene-entity-component library created for the PICO-8 fantasty console.
Stars: ✭ 37 (-38.33%)
Mutual labels:  lua-library
IO-TESTER
A functional test framework
Stars: ✭ 32 (-46.67%)
Mutual labels:  test-framework
xray
An XQuery test framework for MarkLogic
Stars: ✭ 50 (-16.67%)
Mutual labels:  test-framework
tropic
🍍 Test Runner Library
Stars: ✭ 29 (-51.67%)
Mutual labels:  test-framework
cpptest
🛠️ Powerful, yet simple, C++ unit testing framework; new home after https://sourceforge.net/projects/cpptest/
Stars: ✭ 51 (-15%)
Mutual labels:  test-framework
playwright-fluent
Fluent API around playwright
Stars: ✭ 71 (+18.33%)
Mutual labels:  test-framework

u-test

License

u-test is a sane and simple unit testing framework for Lua. It has all essential unit test framework features: defining test cases, test suites, set of build-in assertions, configurable tests output, protected calls and etc.

Top features that are not present in other lua test frameworks

  1. Nice command line interface (like gtest).
  2. Backtrace in failed assertions.
  3. Ordered test execution (as written in source file).
  4. Support 5.1/5.2/5.3 and LuaJIT.
  5. Select particular tests with regexp.

How to install

GitHub

Just copy u-test.lua to your projct or add this repo as submodule.

$ git clone git://github.com/iudalov/u-test

LuaRocks

Just run:

$ luarocks install u-test

How to use

local test = require 'u-test'

-- You can use 'assert' to check invariants.
test.hello_world = function ()
    test.assert(true)
    test.assert(1 ~= 2)
end

-- This is how you can create your first test case
test.addition = function ()
    test.equal(1 + 1, 2)
    test.not_equal("1 + 1", "2")
    test.almost_equal(1 + 1, 2.1, 0.2)
end

-- You can enable custom start_up and tear_down actions
-- Thse actions will be invoked:
-- start_up - before test case
-- tear_down - after test case
local global_state = 0
test.start_up = function () global_state = 1 end
test.tear_down = function () global_state = 0 end

test.dummy1 = function()
    test.equal(global_state, 1)
    test.is_number(global_state)
end

-- You can separate tests by test suites
test.string.format = function ()
    test.equal(string.format("%d + %d", 1, 1), "1 + 1")
    test.not_equal(string.format("Sparky %s", "bark"), "Fluffy bark")
end

test.string.find = function ()
    test.is_nil(string.find("u-test", "banana"))
    test.is_not_nil(string.find("u-test", "u"))
end

-- You can declare test case with parameters
test.string.starts_with = function (str, prefix)
    test.equal(string.find(str, prefix), 1)
end

-- Then, run it with multiple parameters
test.string.starts_with("Lua rocks", "Lua")
test.string.starts_with("Wow", "Wow")

local global_table = {}

-- Each test suite can be customized by start_up and tear_down
test.table.start_up = function ()
    global_table = { 1, 2, "three", 4, "five" }
end
test.table.tear_down = function ()
    global_table = {}
end

test.table.concat = function ()
    test.equal(table.concat(global_table, ", "), "1, 2, three, 4, five")
end

-- you can disable broken test case like this
test.broken.skip = true
test.broken.bad_case = function ()
    test.equal(1, 2)
    there_is_no_such_function()
end

-- obtain total number of tests and numer of failed tests
local ntests, nfailed = test.result()

-- this code prints tests summary and invokes os.exit with 0 or 1
test.summary()

Output

List of all assertions

test.assert(true)
test.equal(1, 1)
test.not_equal(1, 2)
test.is_false(false)
test.is_true(true)
test.is_not_nil("Something")
test.is_nil(nil)
test.is_boolean(true)
test.is_boolean(false)
test.is_string("I am string! look at me!")
test.is_number(3)
test.is_table({"I am table now"})
test.is_function(function () end)
test.is_userdata(userdata_value)
test.error_raised(function() error("error 10") end, "error 10")

Custom assertions

local function is_elephant(animal)
    if animal ~= "elephant" then
        local failure_msg = "Expected elephant, but got "..tostring(animal)
        return false, msg
    end

    return true
end

test.register_assert("is_elephant", is_elephant)

test.is_elephant("dolphin") -- fails!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].