C ++使用boost测试 [英] c++ Using boost test

查看:120
本文介绍了C ++使用boost测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换以下code使用升压单元测试框架:

 的#include<&iostream的GT;
#包括LT&;&的fstream GT;#包括graph.hhINT主(INT ARGC,字符** argv的){
  为const char * IFILE =的argv [1];  图GP;
  gp.read_xml(IFILE);  性病::法院LT&;< 检查节点和边数......其中p其中p的std :: ENDL;
  INT nodes_expected = 16;
  如果(nodes_expected!= gp.nodes()){
    性病::法院LT&;< 测试失败。 <<的std :: ENDL;
    性病::法院LT&;< 预期:<< nodes_expected<<的std :: ENDL;
    性病::法院LT&;< 结果:&所述;&下; gp.nodes()&所述;&下;的std :: ENDL;
  }
  INT edges_expected = 15;
  如果(edges_expected!= gp.edges()){
    性病::法院LT&;< 测试失败。 <<的std :: ENDL;
    性病::法院LT&;< 预期:<< edges_expected<<的std :: ENDL;
    性病::法院LT&;< 结果:&所述;&下; gp.edges()&所述;&下;的std :: ENDL;
  }
  返回0;
}

我读过的文件(<一个href=\"http://www.boost.org/doc/libs/1_46_1/libs/test/doc/html/tutorials/hello-the-testing-world.html\"相对=nofollow称号=升压测试>测试升压),但它并没有告诉我如何在命令行参数的摄取。否则,我很可能使用BOOST_CHECK_EQUAL。


解决方案

 的#include&LT;升压/测试/包括/ unit_test.hpp&GT;
#包括LT&;&的fstream GT;
#包括graph.hh
使用空间boost :: unit_test;BOOST_AUTO_TEST_CASE(test_num_of_nodes)
{
  图GP;
  (框架:: master_test_suite()的argv [1])gp.read_xml;  BOOST_MESSAGE(检查节点和边数...);  BOOST_CHECK_EQUAL(16,gp.nodes());
  BOOST_CHECK_EQUAL(15,gp.edges());
}

How can I convert the following code to use boost unit test framework:

#include <iostream>
#include <fstream>

#include "graph.hh"

int main(int argc, char **argv) {
  const char* ifile = argv[1];

  Graph gp;
  gp.read_xml(ifile);

  std::cout << "Checking number of nodes and edges..."  << std::endl;
  int nodes_expected = 16;
  if(nodes_expected != gp.nodes()) {
    std::cout << "Test Failed." << std::endl;
    std::cout << "Expected: " << nodes_expected << std::endl;
    std::cout << "Result: " << gp.nodes() << std::endl;
  }
  int edges_expected = 15;
  if(edges_expected != gp.edges()) {
    std::cout << "Test Failed." << std::endl;
    std::cout << "Expected: " << edges_expected << std::endl;
    std::cout << "Result: " << gp.edges() << std::endl;
  }
  return 0;
}

I've read the documentation at (Boost Test), but it doesn't tell me how to ingest arguments from the command line. Otherwise, I could probably use BOOST_CHECK_EQUAL.

解决方案

#include <boost/test/included/unit_test.hpp>
#include <fstream>
#include "graph.hh"
using namespace boost::unit_test;

BOOST_AUTO_TEST_CASE( test_num_of_nodes )
{
  Graph gp;
  gp.read_xml( framework::master_test_suite().argv[1] );

  BOOST_MESSAGE( "Checking number of nodes and edges..." );

  BOOST_CHECK_EQUAL(16, gp.nodes());
  BOOST_CHECK_EQUAL(15, gp.edges());
}

这篇关于C ++使用boost测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆