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 279277b18c Unit Tests: Coverage Reporting and Github Actions Integration (#131)
* 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.

* A bunch of smaller syntax tweaks.

* New crash handler catches and logs critical errors!

* Chart editor now has null safety enabled.

* Null safety on all tests

* New Level data test

* Generate proper code coverage reports!

* Disable null safety on ChartEditorState for unit testing

* Update openfl to use latest fixes for crash reporting

* Added unit test to Github Workflow

* Updated unit tests to compile with null safety enabled by inlining assertions.

* Added coverage gutters as a recommended extension

* Impreovements to tests involving exceptions

* Disable a few incomplete tests.

* Add scripts for building unit coverage reports on linux

---------

Co-authored-by: Cameron Taylor <cameron.taylor.ninja@gmail.com>
2023-08-30 18:31:59 -04:00
..
.vscode Unit Test Suite (#119) 2023-08-22 04:27:30 -04:00
assets Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -04:00
source Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -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 Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -04:00
README.md Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -04:00
report-linux.sh Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -04:00
start-linux-native.sh Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -04:00
start-linux-web.sh Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -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
start-win-web.bat Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -04:00
test-cpp.hxml Unit Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -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 Tests: Coverage Reporting and Github Actions Integration (#131) 2023-08-30 18:31:59 -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.

Null Safety

Append each test class with @:nullSafety to prevent crash bugs while developing.

Note that Assert.isNotNull(target) is considered a vlid