Writing unit tests using Google Test

Its been a while since I last made a blog post I guess. In this post I want to talk about what I have been on since then. So, after we discarded the idea of using node.js and node-ffi framework to write our unit tests, David Humphrey was suggested by Ted to write unit tests using google test (gtest). Personally, I liked googletest to write our unit tests far more than writing them in javascript using node-ffi. Before our 0.3 release, all I did was just researched about how to use javascript to write unit tests. And then barely did I understand how the bindings were working. It was almost a non productive release for me because at the end of it, only thing I had was some learning and no actual work that I could submit although I was trying to get some work done. Also, there is very little documentation available on how to use these frameworks.

Using google test is much easier. I started off by reading the documentation available on gtest. The documentation is very helpful. It tells you everything you need to do get googletest working in your project. Since I started reading google documentation a little late after we decided to go with gtest, caitlin and rick already had the C++ bindings and the test fixture ready for us to use them in writing the actual unit tests. Writing unit tests in googletest is fairly easy and straightforward. And I also like the fact that you can disable a test by just adding DISABLED_ keyword before the test name. You can even run the disabled tests by invoking the  test program with –gtest_also_run_disabled_tests  flag. There is an advanced guide available on gtest to learn a whole lot of things about gtest framework.

I planned to start by writing some unit tests for timestamps in cues. I created a new directory called cue-timings in directory ‘unit’ to hold the webvtt test files that will be used in unit tests to test the timestamps. I added two files to start with.


11:12:13.123 –> 14:15:16.456


10:00:11.123 –> 11:00:13.456

And then I wrote a test case file to hold the actual unit tests. A test case file can hold one or many unit tests. gtest guide suggests us to group our tests into test case that reflect the structure of the tested code. The makefile.am was also needed to be modified to include the newly created unit tests. I added these lines where appropriate in the makefile.




and got an error below.

So, I went onto irc for some help. Presumably, my test case file was not being run. Rick told me to add the line below in makefile which, I guess, will tell the gtest that cscuetimings_unittest tests are located in file cscuetimings_unittest.cpp. And it worked beautifully then.

The pull request I sent has been reviewed by a couple of people and I am going to fix whatever needs to be fixed in that and also write the unit tests for test files that was decided in class today. Right now, I am not clear only about the BOM the character test files that i am going to test those. But I will try to finish the rest first and then ask someone else to help me on those ones.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s