Showing posts with label Cpp. Show all posts
Showing posts with label Cpp. Show all posts

Wednesday, 20 September 2017

TrafficControl: Analysing a Simple Google Test Project

To understand Google Test, I created a sample test application using Qt 5.9, that is using Microsoft Visual C 2015 and Google Test.



As for other Qt  projects, it is a good idea to start looking at the pro file:
+= means add module to project when compiling. -= means remove module.
The qt part is removed for this particular project. I assume that it is since no Qt code is to be tested in this project. It is still possible to compile and test when keeping qt in the project (by commenting out the removal clause on line 7). The same is for the app_bundle tag on line 5.

Google Test is added on the first line, using include statement. Let's have a look at the gtest_dependency.pri file.

The syntax is described in the Qt documentation
The syntax is descibedInitially, there are some checks for whether there is a defined GOOGLETEST_DIR on the computer. If not, the compiler will throw an error message to the build console. If there is such a directory, the test project will be compiled for GTest/GMock.

The test cases are listed in tst_firstgoogletestcase.h as separate functions. The tests are sorted into test cases and test sets, making it possible to have several test sets. This will be useful for me, since I want to sort the test cases in TrafficControl.

The cpp main file initiates the test suite.

In the next blog post, I'll try to import the test cases into the TrafficControl project.



Tuesday, 5 September 2017

TrafficControl: Testing Google Test

Now when I got QtTest working, I want to investigate how to use Google Test.

Google Test can be used with Qt Creator, and I need to find out how to use that for two reasons:

  1. Google Test might be more powerful with respect to functions,
  2. Google Test is more well-known than Qt Test and I will probably use it in future projects.

It's pretty simple to create a stand-alone Google Test application:

  1. First, I cloned cloning the GoogleTest repo using "git clone https://github.com/google/googletest.git", 
  2. After that, I created a Google Test project according to the Qt documentation.
  3. After compiling, the test is verifying and asserting the value of 0 and 1.


In the next blog post, I'll look into the files of the project and try to add test cases, and also to include Google test into TrafficControl.