乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 12|回复: 0

在ObjectARX中进行单元测试

[复制链接]

14

主题

202

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
258
发表于 2010-4-23 11:22:00 | 显示全部楼层 |阅读模式
Unit Testing C++  ObjectARX
from:http://www.jlhdevelopment.com/wordpress/2008/12/22/unit-testing-c-autocad-objectarx/
Let me start by saying that coming from a Java/C# development background, I found unit testing in C++ to be a real pain in the arse.  and  are the de facto unit testing frameworks for Java and .NET development. They are simple, easy to use, well documented, and have a decent community around them in case you do get stuck. Unfortunately, a de facto C++ unit testing framework does not exist, and there are so many options that articles such as  exist that compare and contrast some of the more popular frameworks and attempt to point you in the right direction. However, after hours of digging through documentation and playing with various frameworks, I almost gave up trying to get one that would compile and link against an ObjectARX application.
This is a very short overview of how we’ve managed to get unit testing setup for our ObjectARX C++ application. I want to point out from the onset that this is *hopefully* not the easiest or cleanest way to unit test an ObjectARX application, but it does work and is relatively straightforward. I am using Visual Studio 2005 and dynamic linking, your mileage may vary with different compilers and linking options. I’m also assuming you have successfully compiled and tested your ObjectARX application, but if not  for doing that. So, here goes:
[ol]
Install the Boost libraries, usually you would download the source and compile these yourself, but thankfully  has provided binaries for the VS family of compilers . Run the installer to install the appropriate binaries on your system. I selected all of the types of libraries because the Multithread DLL option gave me linker errors. If you want to try selecting only the ones you need, good luck.
Create a new configuration, select Build->Configuaration Manager, then select from the dropdown on the top left. Name it UnitTest or whatever you want, and copy the settings from the Release configuration.
Open the Property Pages for your new configuration.
Under Configuration Properties->General, change Configuration Type to Application (.exe)
Under C/C++->General, add C:\boost\boost_1_36_0 or wherever you installed the Boost libraries to Additional Include Directories.
Under C/C++->Code Generation, make sure Basic Runtime Checks is set to Default.
Under C/C++->Output Files, change the Output Files paths to .\UnitTest/ wherever you see .\Release/
Under Linker->General, change the output file from your arx file to TestYourProject.exe, where YourProject is the name of your ObjectARX application. Also add C:\boost\boost_1_36_0\lib to Additional Library Directories.
Under Linker->System, change SubSystem from /SUBSYSTEM:Windows to /SUBSYSTEM:Console
Now hit apply, hit OK to close the window, and build the new configuration and make sure you don’t get any compiler or linker errors.
Create a new .cpp file, name it Test.cpp or something similar. This will create an entry point for the unit tests. In the body, put this:#include “stdafx.h”
#define BOOST_TEST_MODULE TestYourProjectName
#include
Now, for each class YourClass that you want to write tests for, create a corresponding YourClassTest.cpp similar to the following:#include “stdafx.h”
#include “YourClass.h” #include
BOOST_AUTO_TEST_SUITE(name_of_class_to_test_test);
BOOST_AUTO_TEST_CASE(my_first_test_case)
{
//….some initialization code here
BOOST_CHECK_EQUAL( 2==2, true);
}
BOOST_AUTO_TEST_SUITE_END();
Build with the new UnitTest configuration selected
Add the AutoCAD installation to your path, in my case it is: C:\Program Files\AutoCAD 2007, so that Windows will find the dll’s
Open a command shell and run the TestYourProject.exe from the command line. If successful, you should see the following: “Running x test cases….” followed by the result of the tests.
That’s it, you should now have a way to unit test your ObjectARX applications using the Boost Test library. You also probably want to use a preprocessor command and ifdef all of your *Test classes so that they don’t get included in your production build. Refer to  for a more detailed explanation of the framework.
[/ol]

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 22:05 , Processed in 0.511828 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表