Unit tests in Vala

Simple test

void add_foo_tests () {
    Test.add_func ("/vala/test", () => {
        assert ("foo" + "bar" == "foobar");
    });
}

void main (string[] args) {
    Test.init (ref args);
    add_foo_tests ();
    Test.run ();
}

Compile this with:

valac unit-test.vala

Test using GTK+

void add_foo_tests () {
    Test.add_func ("/vala/test", () => {
        var widget = new Gtk.Button ();
        assert (widget is Gtk.Button);
    });
}

void main (string[] args) {
    Gtk.init (ref args);
    Test.init (ref args);

    add_foo_tests ();

    Idle.add (() => {
        Test.run ();
        Gtk.main_quit ();
        return false;
    });

    Gtk.main ();
}

Compile this with:

valac --pkg gtk+-2.0 unit-test-gtk.vala


Vala/Examples

Projects/Vala/TestSample (last edited 2013-11-22 16:48:25 by WilliamJonMcCann)