Towards a Test Driven Development Framework in Vala Part 6. First Release!

Posted on Thu 31 March 2016 in Vala

Well, it turns out that managing a Rock Band is more time consuming than I first thought, especially if they're getting ready to release their first album. It also turns out that building Debian packages is hard as well, particularly if you're trying to set up a Jenkins CI system to automate the process. Despite all this, I'm only a few weeks behind my initially projected release date and I'm pretty excited to announce that the day has finally come and Version 1.0 of Valadate is now ready for public consumption!

I'll go through the full feature set (warts and all) shortly, but for those who can't wait to dive in, here's how you can install it...

From Source

For the adventurous, you can download the source and build and install it yourself. You will need to have the automake toolchain set up on your system and the development libraries for the following installed:

  • glib-2.0
  • libxml-2.0
  • libxslt
  • json-glib-1.0

You'll also need Gtk-Doc and Valadoc if you want to build the API documentation.

Grab the source:

git clone https://github.com/chebizarro/valadate.git

In the source directory run:

./autogen.sh
make

You can pass the --enable-docs flag to autogen.sh if you have Valadoc and Gtk-Doc installed and it will build the API documentation in the docs directory.

To install, you then just need to run the following with root privileges:

make install

And that's it, you should be ready to roll. Of course, you'll need to go through this process everytime there's a new release so it might be easier to just install it using your system's package manager. Depending on what that is, you can do the following:

Debian

Add the repository's key

curl https://www.valadate.org/jenkins@valadate.org.gpg.key | sudo apt-key add -

Add the following to your Software Sources:

deb https://www.valadate.org/repos/debian valadate main

Then you can install Valadate with:

sudo apt-get update
sudo apt-get install valadate

Fedora 23

Add the following to /etc/yum.repos.d/valadate.repo

[valadate]
name=valadate
baseurl=http://www.valadate.org/repos/fedora/$releasever/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
gpgkey=http://www.valadate.org/jenkins@valadate.org.gpg.key

Then run with root privileges:

dnf update
dnf install valadate

Those are the distributions that are available so far, but there's a Homebrew package for Mac OS X that's more or less ready to push. Given the way Valadate works, a Windows release will probably be a little while off as there are a few platform specific issues to be worked through. If you have favourite platform that you would like to see packaged, submit an issue on GitHub and I'll see what I can do.

So now you've got Valadate, how do you use it?

The easiest way is to create a Sub Class of the TestCase Abstract Class and add test methods to it, which are any that start with test_, have no parameters and return void. These methods will then be detected and executed automatically at runtime.

namespace MyTest {
    public class BookTest : Valadate.Framework.TestCase {

        public void test_construct_book() {

            // Arrange ...

            // Act ...

            // Assert ...
        }
    }
}

To compile, pass the following flags and parameters where mytest-0.vala is the source code file containing the above test.

$ valac --library mytest-0 --gir mytest-0.gir --pkg valadate-1.0 -X -pie -X -fPIE mytest-0.vala

In order for everything to work correctly, the name of the output binary needs to exactly match that of the .gir file (less the file extension). This will then generate an executable which can be run on the Command Line:

$ ./mtest-0

/LibraryBookTest/construct_book: ** Message: mytest-0.vala:15: running

OK

To run the test binary with TAP output pass the --tap flag:

$ ./mtest-0 --tap

# random seed: R02Sddf35dad90ff6d1b6603ccb68028a4f0

1..1

# Start of LibraryBookTest tests

** Message: mytest-0.vala:15: running

ok 1 /LibraryBookTest/construct_book

# End of LibraryBookTest tests

The [Test] annotation and parameters are also available for giving test classes and methods more readable names and for supporting asynchronous tests.

namespace MyTest {
    [Test (name="Annotated TestCase with name")]
    public class MyTest : Valadate.Framework.TestCase {

        [Test (name="Annotated Method With Name")]
        public void annotated_test_with_name () {
            assert_true(true);
        }


        [Test (name="Asynchronous Test", timeout=1000)]
        public async void test_async () {
            assert_true(true);
        }

        [Test (skip="yes")]
        public void skip_test () {
            assert_true(false);
        }
    }
}

$ ./mtest-0 --tap

1..3
# Start of Annotated TestCase with name tests
ok 1 /Annotated TestCase with name/Annotated Method With Name
ok 2 /Annotated TestCase with name/Asynchronous Test
ok 3 /Annotated TestCase with name/skip_test # SKIP Skipping Test skip_test
# End of Annotated TestCase with name tests

Testing Gtk applications

If you want to test Gtk based applications you will need to use the valadate-gtk package (available in the same repository). It's usage is almost identical:

$ valac --library mytest-0 --gir mytest-0.gir --pkg valadate-gtk-1.0 -X -pie -X -fPIE mytest-0.vala

The valadate-gtk package makes sure the Gtk Test environment is properly loaded and configured, otherwise you will get all sorts of funky errors.

RTFM

The Wiki is pretty scant at the moment but will eventually have detailed instructions on installing and setting up your toolchain with Valadate as well as integrating it with Continuos Integration systems.

There are a number of sample projects available here which showcase Valadate's features and how to use it with different toolchains and platforms. This will be continuously updated as new features are added.

The API reference for Vala can be found here and for C here. These documents are automatically generated by Jenkins whenever a new release is made so should always be up-to-date.

Next steps...

Obviously (hopefully), there will be a tsunami of bug reports once people start using it and finding them. I've tested it on a large array of platforms but there's no saying what will happen once it's in the wild. Aside from that, I am very much keen to get to work on adding BDD support via Gherkin and gradually replacing some of the crustier and more unwieldly elements of GTest under the hood. This will have to come in the time I can find between my regular consulting work which has recently taken off in a big way, and managing a Rock band that's just about to put an album out. Good times!

We salute you