CMake创建CTest工程

                在CMake工程顶层目录内的CMakeLists.txt文件中添加最后一行,使得目录结构中包含test目录,并且编译完成时会在build目录下产生test_bin目录。

cmake_minimum_required(VERSION 2.8)project (your_project_name)add_subdirectory(src bin)add_subdirectory(test test_bin)


step2

在test目录下的CMakeLists.txt文件中就像src目录下的一样配置,你需要什么库,就加在里面。不过需要一点下面的设置

include(CheckFunctionExists)include(CheckCXXSourceCompiles)include(CheckLibraryExists)include(CPack)enable_testing()...add_test(name your_test command your_test)



step3

test目录下创建一个main函数,里面编写测试代码,我尝试着使用boost的test框架,暂时还没有成功,因此使用了一个宏(来源于CppCMS的作者Artyom)


/////                                                                             //  Copyright (C) 2008-2010  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>     //                                                                             //  This program is free software: you can redistribute it and/or modify       //  it under the terms of the GNU Lesser General Public License as published by//  the Free Software Foundation, either version 3 of the License, or//  (at your option) any later version.////  This program is distributed in the hope that it will be useful,//  but WITHOUT ANY WARRANTY; without even the implied warranty of//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//  GNU Lesser General Public License for more details.////  You should have received a copy of the GNU Lesser General Public License//  along with this program.  If not, see <http://www.gnu.org/licenses/>./////#ifndef CPPCMS_TEST_H#define CPPCMS_TEST_H#include <stdexcept>#include <sstream>#define TEST(X)         \ do {         \  if(X) break;       \  std::ostringstream oss;      \  oss << "Error " << __FILE__ << ":"<<__LINE__ << " "<<#X; \  throw std::runtime_error(oss.str());    \ }while(0) #endif

使用这个宏很简单,比如:

TEST(result >= 66);


step4
进入build目录编译,编译成功后,进入test_bin目录运行ctest,屏幕上会看到一些简要的结果信息:

Test project /home/chenshu/work/CommonService/trunk/c++/PipeLine2/build/test_bin    Start 1: similarity_test1/1 Test #1: similarity_test ..................***Failed    0.31 sec0% tests passed, 1 tests failed out of 1Total Test time (real) =   0.89 secThe following tests FAILED:   1 - similarity_test (Failed)Errors while running CTest

并且会产生Testing/Temporary/目录,该目录下包含了几个文件,CTestCostData.txt  LastTest.log  LastTestsFailed.log,详细测试信息都在其中。








           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值