work in progress, hold tight...
Micro test framework for Fallout 2
#include "Waterchip.h"
#include "MyMod/InventoryHelper.h"
describe("Inventory Helper") begin
variable critter;
setup begin
critter = create_object(PID_PHIL, 0, 0);
clear_inventory(critter);
end
test("inventory should be empty") begin
expect(inven_count(critter)) to_equal(0);
expect(inven_count(critter)) not_to_equal(69);
end
test("can add weapon to dude's inventory") begin
give_weapon(critter, PID_SHOTGUN);
expect(inven_count(critter)) to_equal(1);
end
end
- Installation
- Getting Started Guide
- Syntax Reference
expect()
Assertionsto_equal
/not_to_equal
to_contain
(support for strings and arrays and maps)to_have_length
to_be_greater_than
to_be_greater_than_or_equal_to
to_be_less_than
to_be_less_than_or_equal_to
to_have_inventory_item
...
- Download latest
Waterchip.h
-
Create a new global script for each group of tests you would like to create.
e.g.
scripts/gl_MyMod_InventoryHelperTest.ssl
-
Include the Waterchip testing framework:
#include "Waterchip.h"
-
Include your own code from header files:
// You should generally pull the code you want to test out into headers. // There are also ways to interact with your running scripts, however. #include "MyMod/InventoryHelper.h"
-
Add a
describe()
to describe your group of tests in this file:// Let's say that you have inventory helper procedures you want to test describe("MyMod Inventory Helper") begin // Your tests will go here end
-
Add a
test()
to describe a specific piece of functionality you want to test:describe("MyMod Inventory Helper") begin test("can clear inventory") begin // Your test and assertions will go here end end
-
Arrange everything that you need for your test to run:
describe("MyMod Inventory Helper") begin // Variables are declared inside of the describe() above tests variable critter; test("can clear inventory") begin // To test clearing inventory, we need a critter! critter = create_object(PID_PHIL, 0, 0); add_obj_to_inven(critter, create_object(PID_SHOTGUN, 0, 0)); // Now we have a critter with some inventory! // Next, we want to call our inventory helper procedures // to verify if they work! end end
-
Now that you have your critter setup, time to call your code to verify it works:
describe("MyMod Inventory Helper") begin variable critter; test("can clear inventory") begin critter = create_object(PID_PHIL, 0, 0); add_obj_to_inven(critter, create_object(PID_SHOTGUN, 0, 0)); // Call *something* from your code to test! // This is just a simple example. call InventoryHelper_ClearInventory(critter); end end
-
Make assertions to verify that your code works:
describe("MyMod Inventory Helper") begin variable critter; test("can clear inventory") begin critter = create_object(PID_PHIL, 0, 0); add_obj_to_inven(critter, create_object(PID_SHOTGUN, 0, 0)); // Add an assertion *before* your procedure // to verify that your test is setup properly expect(inven_count(critter)) to_be_greater_than(0) call InventoryHelper_ClearInventory(critter); // Assert that it worked! expect(inven_count(critter)) to_equal(0) end end
TODO: add
to_be_greater_than
assertion -
Compile your code & run the game!
-
Look in your
debug.log
and you should see something like this:[Waterchip] [MyMod Inventory Helper] [can clear inventory] [PASS] [Waterchip] [MyMod Inventory Helper] [Tests passed] [1 passed, 0 skipped]