Giter Site home page Giter Site logo

love-test's Introduction

Lövetest

Basic testing suite for the Löve APIs, based off of this issue.

Currently written for Löve 12, which is still in development.


Features

  • Simple pass/fail tests in Lua with minimal setup
  • Ability to run all tests with a simple command
  • Ability to see how many tests are passing/failing
  • Ability to run a subset of tests
  • Ability to easily run an individual test
  • Ability to see all visual results at a glance
  • Automatic testing that happens after every commit
  • No platform-specific dependencies / scripts

Running Tests

The testsuite aims to keep things as simple as possible, and just runs all the tests inside Löve to match how they'd be used by developers in-engine. To run the tests, download the repo and then run the main.lua as you would a Löve game, i.e:

WINDOWS: & 'c:\Program Files\LOVE\love.exe' PATH_TO_TESTING_FOLDER --console
MACOS: /Applications/love.app/Contents/MacOS/love PATH_TO_TESTING_FOLDER
LINUX: ./love.AppImage PATH_TO_TESTING_FOLDER

By default all tests will be run for all modules.
If you want to specify a module/s you can use:
--runSpecificModules filesystem,audio
If you want to specify only 1 specific method only you can use:
--runSpecificMethod filesystem write

All results will be printed in the console per method as PASS, FAIL, or SKIP with total assertions met on a module level and overall level.

When finished, the following files will be generated in the /output directory with a summary of the test results:

An example of all types of output can be found in the /examples
The visual results of any graphic tests can be found in /output/actual


Architecture

Each method and object has it's own test method written in /tests under the matching module name.

When you run the tests, a single TestSuite object is created which handles the progress + totals for all the tests.
Each module has a TestModule object created, and each test method has a TestMethod object created which keeps track of assertions for that method. You can currently do the following assertions:

  • assertNotNil(value)
  • assertEquals(expected, actual, label)
  • assertNotEquals(expected, actual, label)
  • assertRange(actual, min, max, label)
  • assertMatch({option1, option2, option3 ...}, actual, label)
  • assertGreaterEqual(expected, actual, label)
  • assertLessEqual(expected, actual, label)
  • assertObject(table)
  • assertPixels(imgdata, pixeltable, label)

Example test method:

-- love.filesystem.read test method
-- all methods should be put under love.test.MODULE.METHOD, matching the API
love.test.filesystem.read = function(test)
  -- setup any data needed then run any asserts using the passed test object
  local content, size = love.filesystem.read('resources/test.txt')
  test:assertNotNil(content)
  test:assertEquals('helloworld', content, 'check content match')
  test:assertEquals(10, size, 'check size match')
  content, size = love.filesystem.read('resources/test.txt', 5)
  test:assertNotNil(content)
  test:assertEquals('hello', content, 'check content match')
  test:assertEquals(5, size, 'check size match')
  -- no need to return anything or cleanup, GCC is called after each method
end

After each test method is ran, the assertions are totalled up, printed, and we move onto the next method! Once all methods in the suite are run a total pass/fail/skip is given for that module and we move onto the next module (if any)

For sanity-checking, if it's currently not covered or it's not possible to test the method we can set the test to be skipped with test:skipTest(reason) - this way we still see the method listed in the test output without it affected the pass/fail totals


Coverage

This is the status of all module tests currently.

Module Written Todo Skipped
🟡 audio 26 2 0
🟡 data 7 5 0
🟡 event 4 1 1
🟡 filesystem 28 1 2
🟡 font 4 3 0
🟡 graphics 92 13 2
🟡 image 3 2 0
🟡 math 17 3 0
🟡 physics 22 6 0
🟡 sound 2 2 0
🟢 system 6 0 2
🟡 thread 3 2 0
🟢 timer 6 0 0
🟡 video 1 1 0
🟢 window 34 0 2

The following modules are not covered as we can't really emulate input nicely:
joystick, keyboard, mouse, and touch


Todo

Modules with some small bits needed or needing sense checking:

  • love.data - packing methods need writing cos i dont really get what they are
  • love.event - love.event.wait or love.event.pump need writing if possible I dunno how to check
  • love.font - newBMFontRasterizer() wiki entry is wrong so not sure whats expected
  • love.graphics - still need to do tests for the main drawing methods
  • love.image - ideally isCompressed should have an example of all compressed files love can take
  • love.math - linearToGamma + gammaToLinear using direct formulas don't get same value back
  • love.*.objects - all objects tests still to be done
  • love.graphics.setStencilTest - deprecated, replaced by setStencilMode()

Future Goals

  • Tests can compare visual results to a reference image (partially done)
  • Ability to test loading different combinations of modules
  • Performance tests

love-test's People

Contributors

bauumm avatar ellraiser 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.