【问题标题】:The executable test file is not running the tests可执行测试文件未运行测试
【发布时间】:2016-06-27 15:22:59
【问题描述】:

我创建了一个项目:

// func.h :
#ifndef FUNCS_H_
#define FUNCS_H_

int addInts(int i, int j);

#endif /* FUNCS_H_ */

// func.cpp
#include "func.h"

int addInts(int i, int j) {
    return i + j;
}

// main.cpp
#include "func.h"

#include <iostream>

int main() {
    std::cout << addInts(5, 7) << std::endl;
    return 0;
}

//makefile
OBJS := \
    main.o \
    func.o

CXX := g++

CXX_FLAGS := -Wall -Werror -Wextra -std=c++11

all: main_prj

main_prj: $(OBJS)
    $(CXX) $(OBJS) -lm -o main

-include $(OBJS:.o=.d)

%.o: %.cpp
    $(CXX) -c $(CXX_FLAGS) $*.cpp -o $*.o

clean:
    rm -f main $(OBJS)

我还为该功能创建了一个测试(增强测试):

// test/main_test.cpp
#define BOOST_TEST_MODULE main_test
#include <boost/test/included/unit_test.hpp>

//____________________________________________________________________________//


// FIXTURES ...

//____________________________________________________________________________//

// test/addInts/addInts_test.cpp
#include <boost/test/unit_test.hpp>

#include "../../func.h"

BOOST_AUTO_TEST_CASE(addInts_5_7) {
    int addInts_5_7 = 5 + 7;
    BOOST_CHECK_EQUAL(addInts_5_7, addInts(5, 7));
}

// test/makefile
OBJS_TEST := \
    main_test.o \
    addInts/addInts_test.o \
    ../func.o

CXX_TEST := g++

CXX_FLAGS_TEST := -Wall -Werror -Wextra -std=c++11

all_test: main_test_prj

main_test_prj: $(OBJS_TEST)
    $(CXX_TEST) $(OBJS_TEST) -lm -o main_test

-include $(OBJS_TEST:.o=.d)

%.o: %.cpp
    $(CXX_TEST) -c $(CXX_FLAGS_TEST) $*.cpp -o $*.o

clean_test:
    rm -f main_test $(OBJS_TEST)

现在,make 命令可以工作了,所以它们会清理所有创建的文件,或者创建 o 文件和可执行文件。当我运行主文件时,输出是正确的: 12 ;但是当我运行 main_test 文件时,输出有点奇怪:

Running 1 test case...

*** No errors detected

我希望输出运行测试和 OK/KO,或者通过/不通过...我不知道我做错了什么。谁能帮帮我?

【问题讨论】:

    标签: c++ c++11 makefile


    【解决方案1】:

    你有一个测试。

    输出表明运行了一项测试,并且没有发现错误。

    此输出显示为documented

    这里没有问题。

    虽然可悲的是,the documentation on how to change this output 相当缺乏……

    【讨论】:

    • 你是对的。没注意,但我添加了更多测试,它似乎输出相同的东西,除了测试的数量,如果一个失败,那么打印错误,在哪里和什么;但是有没有办法看到每个测试名称和 ok/ko 的“美丽”输出?
    • ...没关系,拥有 OK 并不重要... :)
    • @sop 如果你想要某种特定类型的输出,你必须告诉我们它是什么。不过,正如我在答案底部所指出的那样,我认为无论如何我都无法帮助您。 :) Boost 邮件列表可能会提供更多帮助。
    • 是的,你做到了 :) 我在考虑类似 googletest 的输出(请参阅this 以查看示例),但记录到 xml 也可以
    猜你喜欢
    • 2019-12-06
    • 2015-10-31
    • 2011-06-06
    • 2019-02-10
    • 2016-09-02
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多