Godot Version
4.2
Question
Hi I am trying to create a Unit test for my gdextension. For this i am using doctest.h. I added everything and was able to test simple things like:
TEST_CASE("Example test") {
CHECK(1 == 1);
}
Of course I want to test more complex stuff like for example the class Summator : public RefCounted example → Custom modules in C++ — Godot Engine (stable) documentation in English
In this tutorial they also create a unit test:
// test_summator.h
#ifndef TEST_SUMMATOR_H
#define TEST_SUMMATOR_H
#include "tests/test_macros.h"
#include "modules/summator/summator.h"
namespace TestSummator {
TEST_CASE("[Modules][Summator] Adding numbers") {
Ref<Summator> s = memnew(Summator);
CHECK(s->get_total() == 0);
s->add(10);
CHECK(s->get_total() == 10);
s->add(20);
CHECK(s->get_total() == 30);
s->add(30);
CHECK(s->get_total() == 60);
s->reset();
CHECK(s->get_total() == 0);
}
} // namespace TestSummator
#endif // TEST_SUMMATOR_H
however they use #include “tests/test_macros.h”. Which i do not have. Also they call the test by using ./bin/<godot_binary> --test --source-file=“test_summator” --success which i do not do.
I created defined my own program for testing in the Sconstruct file called MyGodotTest so if i want to build and test i do scons and then just start ./MyGodotTest . However if i do this i get an error with Ref s = memnew(Summator); → FATAL ERROR: test case CRASHED: SIGSEGV - Segmentation violation signal I think this is duo to me not initialising godot or something?
Does anybody have some tipps. Or should I just copy all the files from "tests/ " into my sourcecode so i can use test_macros.h ? I feel like everything these tutorials show is wrong if you use Godotcpp