-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests #1862
Add unit tests #1862
Conversation
Tested on macOS and it works apart some tests failing. Made a PR for |
Changed It would be nice if someone could test it if it works on Linux. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, you can add the target unit-tests to main CMakeLists.txt like cpp-tests and build it in github ci like: https://github.com/axmolengine/axmol/blob/dev/.github/workflows/build.yml#L100
EDIT: since unit-tests is a console app, you can also run it after build success on github ci
Added to the workflows, but lets not enable test running for now, because not all tests pass (issues like #1863). Lets merge this PR first, then I'll make a separate PR to fix the tests and enable the running. |
merged |
Maybe you misunderstood me... I've meant lets merge this PR (#1862) first, then I'll make the fixes and enable running unit tests in a separate PR. |
seems all intel cpu desktop contains macos, windows, linux build will error |
ok, let's merge first |
This PR adds unit tests by introducing a new
unit-tests
app.Why?
Right now the only way to test the engine is either by hands or
cpp-tests
, which is an unusable nightmare. It's not automated, with bad and slow UX, you have no idea what the tests are testing or how they are supposed to look, etc. The first and a primary tool for non visual tests should be unit tests. It must be fully automatic, fast, easy to use and easy to add and write new tests.How?
This PR adds
unit-tests
app. It's a console app that automatically runs a bunch of tests and at the end prints out if all tests pass. If tests do not pass, it shows which fail, give you source file location for the failing test and gives the reasons why it fails. The app also uses exit codes to signal if tests pass, so this can be used in a CI/CD environments.The app itself uses doctest for writing unit tests. It's pretty simple, but has a lot of nice features. I've looked for something simple to use, and that would integrate easily. Looked at several alternatives, but they either were not maintained anymore or were too complex, and doctest was the only choice.
How it helps me?
You can develop new engine features or fix bugs by simply working on
unit-tests
project. You write some code, add tests for it and instantly know if your new code works or if it breaks some existing functionality. This will improve iteration times, and allow you to be sure that you're not breaking something else in the process.How do the tests look like?
I've converted some tests from
cpp-tests
, you can see them attests\unit-tests\Source\core
. I recommend checkingtests\unit-tests\Source\core\platform\FileUtilsTests.cpp
, since it's closest to how ideal tests should looks like. Quick example:How does running tests looks like?
Success!
Failure...
Future
cpp-tests
tounit-tests
.gfx-tests
app to automate the graphics side of things.Status
cpp-tests
as a first step.tests\unit-tests\Content
is included in the repo. Right now it contains only 3 tiny text files, but I imagine in the future it might contain some larger test assets. So it might be a good idea to setup a separate repo to hold the assets. We can do it now or later.