-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
DrΓ«w edited this page Jul 19, 2024
·
1 revision
- Download the latest version of the library from the releases page.
- Import the library into your project.
- Add the library to your project's resources.
- Done!
- Create a new script in your project.
- Add the following code to the script:
suite("My first test suite", function() {
// Your section will be inserted here!
});
- Find a script you want to test, for example, a script that adds two numbers.
/// @function add_two_numbers(a, b)
/// @param {real} a
/// @param {real} b
/// @returns {real}
function add_two_numbers(a, b) {
return a + b;
}
-
Create a new script anywhere and call it however you want, for example,
test_add_two_numbers
. -
Add a section to the suite:
suite("My first test suite", function() {
section("Add two numbers", function() {
// Your tests will be inserted here!
});
});
- Add some tests to the section:
suite("My first test suite", function() {
section("Add two numbers", function() {
test("1 + 1 = 2", function() {
expect(add_two_numbers(1, 1)).toBe(2);
});
test("2 + 2 = 4", function() {
var _value = add_two_numbers(2, 2);
expect(_value).toBe(4);
expect(_value).toBeLessThan(5);
});
test("2 + 2 != 10", function() {
expect(add_two_numbers(1, 2)).never().toBe(10);
});
});
});
- Run project and see the results in the console. You should see something like this:
------- Add two numbers -------
β 1 + 1 = 2 (0.01ms)
β 2 + 2 = 4 (0.01ms)
β 2 + 2 != 10 (0.01ms)
================================================================
======================= Tests Finished! ========================
Test Suites: 1 passed, 1 total. (100% success)
Tests: 3 passed, 3 total. (100% success)
All tests finished in 0.03ms.
- Done! You have created your first test suite with the GameMaker Testing Library.