I'm trying to run simple unit tests for some C code I'm writing using GLib. I'm trying to do something like:
#include <math.h>
#include <stdio.h>
#include <glib.h>
static void
test_stuff ()
{
g_assert (1 == 1); //Say
}
int main (int argc, char **argv)
{
g_test_init (&argc, &argv);
g_test_add_func ("/TestTest", test_stuff);
return g_test_run();
}
But when I compile (say to a binary called exec) and try to run this using gtester (or even running said binary directly), I get the following error:
me@laptop:tests$ gtester exec
TEST: exec... (pid=6503)
(process:6503): GLib-CRITICAL **: g_test_init: assertion `vararg1 == NULL' failed
FAIL: exec
Terminated
Is there something I'm missing, maybe variables I should pass as I run the tests?
JUnit is an open source framework you can use to write and run tests. It aims to help develop bug-free and reliable code written in Java. JUnit provides test runners that run tests and assertions to test the expected results.
To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).
A unit test typically comprises of three stages: plan, cases and scripting and the unit test itself. In the first step, the unit test is prepared and reviewed. The next step is for the test cases and scripts to be made, then the code is tested.
You're missing an argument to the g_test_init()
function. The docs show the prototype as:
void g_test_init(int *argc,
char ***argv,
...);
and:
... : Reserved for future extension. Currently, you must pass NULL.
So, you need to pass a NULL
as the third argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With