* Initial test suite * Fix some build warnings * Implemented working unit tests with coverage * Reduced some warnings * Fix a mac-specific issue * Add 2 additional unit test classes. * Multiple new unit tests * Some fixins * Remove auto-generated file * WIP on hiding ignored tests * Added list of debug hotkeys * Remove old website * Remove empty file * Add more unit tests * Fix bug where arrows would nudge BF * Fix bug where ctrl/alt would flash capsules * Fixed bug where bf-old easter egg broke * Remove duplicate lines * More test-related stuff * Some code cleanup * Add mocking and a test assets folder * More TESTS! * Update Hmm... * Update artist on Monster * More minor fixes to individual functions * 1.38% unit test coverage! * Even more tests? :O * More unit test work * Rework migration for BaseRegistry * gameover fix * Fix an issue with Lime * Fix issues with version parsing on data files * 100 total unit tests! * Added even MORE unit tests! * Additional test tweaks :3 * Fixed tests on windows by updating libraries. * Set versions for flixel-ui and hamcrest --------- Co-authored-by: Cameron Taylor <cameron.taylor.ninja@gmail.com>
2.2 KiB
Flixel Unit Tests
This is a unit test project using munit. It's good practice to add tests for fixed bugs or new features.
TODO Make sure the unit tests are automatically run on GitHub Actions.
There's a 1:1 mapping between .hx
files in source/
and the unit test project - tests for funkin.Conductor
go into funkin.ConductorTest
etc.
Building
Run one of the test-*.hxml
files in this directory to run the tests on that specific target, e.g. haxe test-cpp.hxml
. Currently supported are:
web
(HTML5)cpp
(Native)
Alternatively, this can be done from within Visual Studio Code - (F1
-> Tasks: Run Task
-> Choose the target to test).
Adding Tests
- Run
haxelib run munit create com.FooBarTest -for com.Foo
- Use
@:allow(full.package.name.ClassName)
to allow a test class to call private functions. - Use
mockatoo.Mockatoo.mock(ClassName)
to mock a class. See Mockatoo docs.
Functions
-
@Before
functions are namedbefore()
-
Each
@Test
function starts withtest
and describes what exactly it tests. This can lead to long function names likeFlxEmitter#testStartShouldNotReviveMembers()
and serves as self-documentation. -
Another thing that helps with self-documentation is adding a comment for tests that are related an issue on GitHub.
@Test // #1203 function testColorWithAlphaComparison()
FunkinTest
base class
Test classes extend FunkinTest
, which is a base class with some utility functions for testing.
step()
step()
advances the FlxGame
exactly one step. This is useful for tests that depend on game time advancing / FlxGame#step()
being executed, such as physics of add()
ed objects, state switches, or just time passing for tweens or timers.
There are two parameters:
steps
- specifies the amount of steps to advance (defaults to 1)callback
- an optional callback function that is executed after each step
testDestroy()
testDestroy()
tests whether an IFlxDestroyable
can safely be destroy()
ed more than once (null reference errors are fairly common here). For this, destroyable
has to be set during before()
of the test class.