1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-04 13:54:22 +00:00
Funkin/tests/unit
Eric 42d8d55067 Unit Test Suite (#119)
* 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>
2023-08-22 04:27:30 -04:00
..
.vscode Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
assets Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
source Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
.gitignore Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
.munit Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
project.xml Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
README.md Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
start-mac-native.sh Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
start-mac-web.sh Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
start-win-native.bat Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
test-cpp.hxml Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
test-web.hxml Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
test.hxml Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
test.hxml-old Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00

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 named before()

  • Each @Test function starts with test and describes what exactly it tests. This can lead to long function names like FlxEmitter#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.