Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux, Google Test (GTest) test environment to build step     - Python developer of time-saving method (Programming)

- Nginx configuration support f4v video format player (Server)

- Physical structure and process disk IO (Linux)

- Linux Open coredump (Linux)

- Fundamentals of the Java virtual machine memory management principles (Programming)

- Oracle users to automatically increase the partition table (Database)

- Heartbeat cluster components Overview (Server)

- MySQL Tutorial: Philosophical Reflections on the unauthenticated user (Database)

- Oracle 11g RAC manually playing GI PSU patch (11.2.0.4.8) (Database)

- JBoss7 configuration - Supports IPv4 and IPv6 dual-stack environment (Server)

- Getting Started with Linux system to learn: how to get the process ID (PID) in the script (Linux)

- Parameters of the extra port MySQL 5.6 (Database)

- Deployment Kubernetes manage Docker example cluster on Ubuntu (Server)

- Linux Shell Understanding and Learning (Linux)

- MySQL appears data too long for column 'name' at row 1 to solve (Database)

- Normal start Lazarus 1.0.8 under Ubuntu (Linux)

- Hard disk encryption to protect data security (Linux)

- To install Python-Pip and Fabric under CentOS / Ubuntu (Linux)

- Oracle JDK installation under Ubuntu Linux (Linux)

- Linux kernel update error, update-initramfs: failed Solution (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:

(Sqrt.cpp)

(Sqrt.h)

(Sqrt_unittest.cpp)

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.
     
         
       
         
  More:      
 
- Linux security settings (Linux)
- Linux shell in back quotes (`) Application (Linux)
- Ubuntu 14.10 Install Ubuntu Touch Music App 2.0 (Linux)
- JDK installation and configuration environment variable under linuxb (Linux)
- Ubuntu prompt / lack of boot space solutions (Linux)
- How to use the character in C ++ without pressing the Enter key to enter the Show (Programming)
- In-depth understanding of capture Node.js garbage collection and memory leaks (Programming)
- Wi-Fi hackers use to attack your seven methods (Linux)
- LogStash log analysis display system (Linux)
- OpenStack / Dev stack with neutron on Ubuntu 14.04 (Server)
- Linux system ARP attack solution (Linux)
- Xshell upload files to achieve Windows host Linux (Linux)
- How to use the Linux command compress JPEG images (Linux)
- MySQL error: ERROR 1175: You are using safe update mode solution (Database)
- How to configure MongoDB replica set (Database)
- Linux environment to configure Apache + Django + wsgi (Server)
- Based kubernetes Construction Docker Cluster Management Comments (Server)
- Ubuntu 14.04 next upgrade to GNOME 3.12 (Linux)
- JavaScript notes --Objects (Programming)
- CentOS 7 open ports (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.