Git Product home page Git Product logo

probo's Introduction

Probo  Lua unit test framework

Compatible with Lua 5.4

Test suite example

local Suite = require("probo/suite")

local runInfo = {}  -- define a `runInfo` table before the do-end scope
do
    -- create a new test suite instance
    -- with <close> defined a garbage-collection cycle is performed at the end this scope
    local test <close> = Suite.New("Probo Suite example")
    local assert <const> = test -- more readable separation between tests and asserts

    test.run = 1                        -- test suite variable

    function test.AlwaysPasses()        -- this is a defined test
        assert:Invokable(test)          -- multiple different asserts are available
    end

    test("Always Fails")                -- test is a decorator
    (function()                         -- with the decorator test names can have spaces
        assert:Fail()
    end)

    function test.FlakyTest()           -- failed tests in the first run can be rerun
        test.run = test.run + 1         -- if the option `rerunFailedTests` is set to true
        assert:Condition(test.run > 2)
    end

    local suiteOptions = {              -- a table with options
        stopOnFail       = false,       -- stops on first failed test
        silent           = false,       -- no output
        rerunFailedTests = true,        -- rerun failed tests
        sortedByName     = false        -- sort tests by name before the test run
    }

    -- run the above defined tests with the given options
    runInfo = test:Run(suiteOptions)    -- runInfo, a table with info about the run
end

Create report

After a run a report can be made with the runInfo created by the run

local Report = require("probo/htmlreport")

local htmlReport = Report.Create(runInfo)  -- create a HTML report

-- save the report
local reportFile = io.open("probo_report.html", "w")
reportFile:write(htmlReport)
reportFile:close()

Mock global functions

By mocking it is possible to temporarily change the behaviour of functions.

local Suite = require("probo/suite")
local Mock = require("probo/mock")

do
    local test <close> = Suite.New("Probo Mock example")
    local assert <const> = test
    local mock <close> = Mock.New()
    
    mock("string.reverse", function(str) return str end)
    
    test("global string.reverse function is mocked")
    (function()
        local given = "not reversed"
        local actual = string.reverse(given)
        assert:Equal(given, actual)
    end)
end

Unit tests

Check out the unit tests that test the Probo unit test package.

License

Apache 2.0

probo's People

Contributors

w13b3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.