Module pico8lib.test

Unit testing

Class TestCase

TestCase:__init (name, setup, teardown) Constructor
TestCase:run ([quiet]) Call all of the test functions that start with "test_" and track failures.
TestCase:assert_throws (fn, expected_message) Call the function fn and assert that an exception is thrown with the given expected message See test/test_test.p8 for examples of how to use this assertion
TestCase:assert_nil (any[, message]) Assert that value is nil
TestCase:assert_not_nil (any[, message]) Assert that value is not nil
TestCase:assert_true (any[, message]) Assert that value is true
TestCase:assert_false (any[, message]) Assert that value is false
TestCase:assert_equal (a, b[, message]) Assert that a is equal to b
TestCase:assert_almost_equal (a, b, tolerance[, message]) Assert that a is almost equal to b, useful for comparing floating points.
TestCase:assert_not_equal (a, b[, message]) Assert that a is not equal to b
TestCase:assert_less_than (a, b[, message]) Assert that a is less than b
TestCase:assert_less_than_or_equal (a, b[, message]) Assert that a is less than or equal to b
TestCase:assert_greater_than (a, b[, message]) Assert that a is greater than b
TestCase:assert_greater_than_or_equal (a, b[, message]) Assert that a is greater than or equal to b
TestCase:assert_boolean (actual[, message]) Assert that 'actual' is a boolean value
TestCase:assert_string (actual[, message]) Assert that 'actual' is a string value
TestCase:assert_number (actual[, message]) Assert that 'actual' is a number value

Class TestSuite

TestSuite:add_test_case (test_case) Add a test case instance to the test suite
TestSuite:new_test_case (name) Create a new test case instance and add it to the test suite
TestSuite:run ([quiet]) Run all of the test cases added to the test suite
TestSuite:make_run_report () Count run and failed tests for all run cases
testsuite.run_suites (suites) A helper function that runs an array of suites, builds a run report and logs the report to STDOUT


Class TestCase

The TestCase class represents a collection of tests to be run for a given context. Subclass TestCase and add functions starting with "test_" then add an instance to a TestSuite instance to run your tests. For an example of how do this, see the Assertions test case in test/test_test.p8.
TestCase:__init (name, setup, teardown)
Constructor

Parameters:

  • name string TestCase naming convention: snake_case
  • setup function Run before each test function is executed, to setup state relevant to the test on the TestCase instance. Override this method as needed in your TestCase subclass.
  • teardown function Run after each test function is executed, to reset state relevant to the test on the TestCase instance. Override this method as needed in your TestCase subclass.
TestCase:run ([quiet])
Call all of the test functions that start with "test_" and track failures.

Parameters:

  • quiet boolean Suppress PASS/FAIL output per test (optional)
TestCase:assert_throws (fn, expected_message)
Call the function fn and assert that an exception is thrown with the given expected message See test/test_test.p8 for examples of how to use this assertion

Parameters:

  • fn function A function to be called
  • expected_message string The exact text of the expected exception
TestCase:assert_nil (any[, message])
Assert that value is nil

Parameters:

  • any a value that is expected to be nil
  • message string override the default error message with message instead (optional)
TestCase:assert_not_nil (any[, message])
Assert that value is not nil

Parameters:

  • any a value that is expected to not be nil
  • message string override the default error message with message instead (optional)
TestCase:assert_true (any[, message])
Assert that value is true

Parameters:

  • any a value that is expected to be true
  • message string override the default error message with message instead (optional)
TestCase:assert_false (any[, message])
Assert that value is false

Parameters:

  • any a value that is expected to be false
  • message string override the default error message with message instead (optional)
TestCase:assert_equal (a, b[, message])
Assert that a is equal to b

Parameters:

  • a the actual object
  • b the expected object
  • message string override the default error message with message instead (optional)
TestCase:assert_almost_equal (a, b, tolerance[, message])
Assert that a is almost equal to b, useful for comparing floating points.

Parameters:

  • a number the actual floating point value
  • b number the expected floating point value
  • tolerance number the absolute variance allowed between a and b
  • message string override the default error message with message instead (optional)
TestCase:assert_not_equal (a, b[, message])
Assert that a is not equal to b

Parameters:

  • a the actual object
  • b the undesired object
  • message string override the default error message with message instead (optional)
TestCase:assert_less_than (a, b[, message])
Assert that a is less than b

Parameters:

  • a the actual value
  • b the upper limit
  • message string override the default error message with message instead (optional)
TestCase:assert_less_than_or_equal (a, b[, message])
Assert that a is less than or equal to b

Parameters:

  • a the actual value
  • b the upper limit
  • message string override the default error message with message instead (optional)
TestCase:assert_greater_than (a, b[, message])
Assert that a is greater than b

Parameters:

  • a the actual value
  • b the lower limit
  • message string override the default error message with message instead (optional)
TestCase:assert_greater_than_or_equal (a, b[, message])
Assert that a is greater than or equal to b

Parameters:

  • a the actual value
  • b the lower limit
  • message string override the default error message with message instead (optional)
TestCase:assert_boolean (actual[, message])
Assert that 'actual' is a boolean value

Parameters:

  • actual the value to test for type
  • message string override the default error message with message instead (optional)
TestCase:assert_string (actual[, message])
Assert that 'actual' is a string value

Parameters:

  • actual the value to test for type
  • message string override the default error message with message instead (optional)
TestCase:assert_number (actual[, message])
Assert that 'actual' is a number value

Parameters:

  • actual the value to test for type
  • message string override the default error message with message instead (optional)

Class TestSuite

The TestSuite class is a collection manager for test cases. Add test case instances to a TestSuite using add_test_case, then call the run_suites function to run the tests.
TestSuite:add_test_case (test_case)
Add a test case instance to the test suite

Parameters:

  • test_case TestCase An instance of a subclass of TestCase
TestSuite:new_test_case (name)
Create a new test case instance and add it to the test suite

Parameters:

  • name string name for the new test case

Returns:

    TestCase the new test case
TestSuite:run ([quiet])
Run all of the test cases added to the test suite

Parameters:

  • quiet boolean Suppress PASS/FAIL output per test (optional)
TestSuite:make_run_report ()
Count run and failed tests for all run cases

Returns:

    table of run and failed counts
testsuite.run_suites (suites)
A helper function that runs an array of suites, builds a run report and logs the report to STDOUT

Parameters:

  • suites
generated by LDoc 1.5.0 Last updated 2024-09-08 14:28:56