Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Linux, Google Test (GTest) test environment to build step     - Redmine Installation (Linux)

- How Ubuntu Snappy Core 2 running on Raspberry Pi (Linux)

- Select helps secure the system network management tools (Linux)

- Using Linux stat command to view the files (Linux)

- CentOS source installation GitLab Chinese Version (Server)

- Python dictionary applications get built-in method (Programming)

- CentOS 5.3 under broadcom NIC dual activation issues (Linux)

- JDK installation notes under CentOS (Linux)

- The YUM package management under Linux (Linux)

- redis main building and disaster recovery from a cluster deployment (Database)

- Precautions against hackers Linux environment (Linux)

- Python2 ---- function using dictionaries (Programming)

- Kubernetes resolve application deployment model (Server)

- RMAN parameters of ARCHIVELOG DELETION (Database)

- Oracle Duplicate build DataGuard (Database)

- Linux log management make the system more secure (Linux)

- Btrfs file system repair techniques (Linux)

- Install RAID 6 (Striping double distributed parity) (Linux)

- MongoDB3.0.x version of the user authorization profile (stand-alone environment) (Database)

- Linux System Tutorial: How to browse the Linux command line, weather forecast (Linux)

  Linux, Google Test (GTest) test environment to build step
  Add Date : 2018-11-21      
  This article describes the procedure of setting up unit testing tools Google Test (GTest) in the Linux operating system in the test environment. In this paper, a basic tutorial Google Test uses. Before using Google Test in Linux, you need to have some understanding of knowledge as follows:

(1) C / C ++ programming

(2) makefile preparation

(3) Linux command line

(4) GTEST background knowledge: it is used to do? It is what language? Some of its basic grammar? and many more

Above do not require knowledge of practice makes perfect, as long as the entry-level to reach, use GTEST not charge any effort, after all, is not a high threshold GTEST tool. Closer to home, we have to follow the steps one by one to explain:

Step 1: Download GTEST

Download link is: https: //code.google.com/p/googletest/downloads/list

The latest version is GTEST gtest-1.7.0.zip, so we will in this paper as an example to explain this version.

Step 2: Understanding Folder

After you download and unzip, you will see a folder gtest-1.7.0

So many documents at first glance does little people scratching their heads. In fact, GTEST provided support for a number of different platforms, such as msvc folder is used in Microsoft Visual Studio, xcode folder for Mac Xcode, codegrear folder for Borland C ++ Builder, in a Linux environment, we It is to make use of the contents of the folder.

Step 3: remove unnecessary files

We've talked about in the previous step, a lot of documents to support different platforms, in order to keep it simple program to avoid confusion audition, we all do not need to delete all the files in this step, retaining only what we need. In fact, we only need four folders, as shown below. The rest of the file and the folder to delete all (this step is not necessary, but we got a little older programmer is concerned, does not allow a bunch of unused code in it ~).

Our program more refreshing.

Step 4: rewrite the Makefile

At this point, if you go to make a folder, through the command line $ make && ./sample1_unittest command, you can see the results of the test. However, if you open the Makefile look, you will find that this applies only to compile makefile sample1, if I add a test source document? But also to re-write makefile, too much trouble. Thus, in this step, we redrafting Makefile.

Back we talked about, now only four folders (include, make, samples, src), which now make only a file should be overwritten, it did not need to stay up this folder. Then, in Step 4, the first thing you have to do is to make the folder, along with the inside of the Makefile delete all ...... Then, enter the samples folder, create a file yourself, called Makefile

Then, open the Makefile file, write the following, as shown (do not put the figure line number is also written into the oh ~). This new Makefile is just now being rewritten us to remove from the Makefile, if you're curious, then you can compare the differences between them, which involves some makefile syntax and function, if not familiar, you may need to spend a few minute check data to understand them.

Note that the figure in the Makefile rewrite line 32, we compile the cpp file name suffix, and give examples of the original ending was to cc. Therefore, you need to do one thing, is to sample1.cc file name to sample1.cpp, the file name to the sample1_unittest.cc sample1_unittest.cpp, it's done.

Now we have three folders (include, src, samples), a program of our own tested on sample folder. This folder name looked relatively unhappy, you can change it to mycode or testcode, then GTEST root folder name gtest-1.7.0 can also be changed to the class mygtest to meet our perfectionist demand.

Now, enter the command line to compile perform operations: $ make && ./run_test, you can see the result

Step 5: Add your test function

To the above step, in fact, our test environment has been set up is completed. If you have a function you want to be a test, you can continue with Step 5.

Suppose we now have a test function sqrt.cpp and its headers sqrt.h, their content is as follows:




Test the role of this document is to calculate the square root of an arbitrary positive integer, algorithm complexity in log (n) level. Mycode above three files in the folder, and then make && ./run_test compile run, you can see the results:

Summary: After the complete environment to build, test each time a file xxx.cpp and its xxx.h file, maybe put into mycode folder, then write xxx_unittest.cpp test files, but also inside. Then to this directory with the command line, make && ./run_test it should be easier than most to open a lot of time to make it? To test, we only need three files into mycode, then enter the command line directory make && ./run_test to complete the test. The following figure is now my mycode the folder. xxx_unittest.cpp the file name is not fixed, taking into something it does not matter, but it is easier to identify which file is which function under test only.

Of course, Google Test is a very powerful tool, but using the above explain its most basic function, as well as to build a simple environment. In fact, the document is needed and that the remaining three files mentioned in Step 4 of the folder contents, proper rewrite, you can achieve more powerful. The wait will have the opportunity to write it.
- Kali Linux 2.0 U disk installation errors Your installation cd-rom could not be mounted (Linux)
- sqlplus connect to Oracle (Database)
- PF_RING 6.0.2 compiled and installed on Redhat 6.3 x86_64 (Linux)
- Linux uses a screen recording under RecordMyDesktop (Linux)
- MongoDB replication instance (Database)
- What have we learn from the front-end application Nodejs (Programming)
- netfilter- in kernel mode network packet operation (Linux)
- Easily create RPM packages using the FPM (Linux)
- ASM required disk format process in Solaris platforms (Linux)
- Let you Fun Ubuntu desktop eleven weapon (Linux)
- Recover Ubuntu 14.04 wakes up from standby in case mouse keyboard appears dead (Linux)
- Linux system security (Linux)
- Linux iptables port mapping settings (Server)
- Golang use Oracle database on Ubuntu 14.04 (Linux)
- Oracle Linux 6.4 installed Oracle 11gR2 + RAC + ASM (Database)
- OpenStack Folsom create an instance of the failure of the Quota Fixed_IP articles (Server)
- MariaDB 10 Multi-source replication (Database)
- HBase table data processing tab (Database)
- SQLite3 simple operation (Database)
- Distributed File System using MogileFS (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.