升压测试无输出

发布于 2024-10-15 19:14:38 字数 1028 浏览 5 评论 0原文

我正在尝试使用 boost 测试库来实现单元测试。我首先阅读了 boost 站点上的手册。之后,我在我现有的项目之一中制作了一个简单的测试程序。我面临的唯一问题是我无法看到测试结果。我确信我做错了一些事情:)但我无法弄清楚这一点。 的项目的详细信息

以下是我使用 Visual Studio8 : 我有一个名为 MyProject.sln 的解决方案

以及其他项目,我有一个名为 MyDLL.vcproj 的项目(该项目的类型是 DLL

与 MYDLL proj 中的其他文件一起,我添加了一个新的 cpp 文件名 MyTest.cpp,该文件包含以下代码:

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
//#define BOOST_TEST_MODULE MyTestTestModue  //no need for this maro if above macro is used
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(SampleTC)
{
    BOOST_CHECK(true);
};    

我在 MYDLL 项目属性表中进行了以下更改

C++ -> General -> Additional Include Dependencies = D:\MyProject\Boost\boost\test
Linker -> General -> Additional Libray Directories = D:\MyProject\Boost\lib\win32\Debug
Linker -> System -> SubSystem = (/SUBSYSTEM:CONSOLE)

我阅读了 中给出的所有编译详细信息手动,但仍然无法获得输出。理想情况下,我想将 Boost 测试用作独立库(UTF 的动态库变体)。

I am trying to implement unit test with boost test libraries. I started by reading the manual at the boost site. After this i make a simple test program in one of my already existing project. The only problem which i face is that i am unable to see the test result. I am sure that i am making some thing wrong :) but i am unable to figure that. Following are the details of my project

I am using visual studio8 for this:
I have a solution named MyProject.sln

Along with other projects i have a project named MyDLL.vcproj (The type of this project is DLL)

Along with other files in MYDLL proj i add a new cpp file name MyTest.cpp, the file contains the following code:

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
//#define BOOST_TEST_MODULE MyTestTestModue  //no need for this maro if above macro is used
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(SampleTC)
{
    BOOST_CHECK(true);
};    

I make following changes in MYDLL project property sheet

C++ -> General -> Additional Include Dependencies = D:\MyProject\Boost\boost\test
Linker -> General -> Additional Libray Directories = D:\MyProject\Boost\lib\win32\Debug
Linker -> System -> SubSystem = (/SUBSYSTEM:CONSOLE)

I read all the compilation details given in the manual, but still unable to get the output. Ideally i want to use the Boost test as a standalone lib (Dynamic library varian of UTF).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味拾荒者 2024-10-22 19:14:38

我确信我正在做一些事情
错误:)

实际上,我认为问题在于你正在做正确的事情。

您的测试通过了,因为检查的值为 true,并且默认情况下 Boost.Test 仅输出有关失败测试的信息。您需要设置日志级别,可以通过以下两种方式之一完成:将 --log_level=all 作为测试可执行文件的选项传递,或设置环境变量 BOOST_TEST_LOG_LEVEL > 到全部

请参阅 文档的此页了解所有运行时参数。

编辑:它实际上是 --log_level (中间有一个下划线)

I am sure that i am making some thing
wrong :)

Actually, I think the problem is you are making something right.

Your test passes, because the value checked is true, and by default Boost.Test only outputs information about tests that have failed. You need to set the log level, which can be done one of two ways: passing --log_level=all as an option the the test executable, or setting the environment variable BOOST_TEST_LOG_LEVEL to all.

See this page of the documentation for all the run time parameters.

Edit: It's actually --log_level (with an underscore in the middle)

挽清梦 2024-10-22 19:14:38

我们的单元测试是通过编译后工具调用的;因此我们无法轻松地将参数传递给 EXE(不更改工具配置并影响所有测试)。

因此,设置日志级别阈值的另一种方法是从代码中调用 Boost 单元测试记录器单例:

boost::unit_test::unit_test_log_t::instance().set_threshold_level( boost::unit_test::log_messages );

为了增加乐趣,请输出显示消息的文件名和行号:

 #define MY_BOOST_TEST_MESSAGE( msg ) BOOST_TEST_MESSAGE( `__FILE__` << `__LINE__` << " " << msg )

Our unit tests are called via a tool post-compile; so we cannot easily pass a parameter to the EXE (without changing the tool configuration and affecting all tests).

So another way of setting the log-level threshold is to call the Boost unit-test logger singleton from the code:

boost::unit_test::unit_test_log_t::instance().set_threshold_level( boost::unit_test::log_messages );

For added fun, output the file name and line number where your message is displayed:

 #define MY_BOOST_TEST_MESSAGE( msg ) BOOST_TEST_MESSAGE( `__FILE__` << `__LINE__` << " " << msg )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文