Post Build Event for CxxTest in Visual Studio 2005
来源:互联网 发布:windows posready 7 编辑:程序博客网 时间:2024/05/21 17:35
I'm trying to write some unit tests for my c++ code in VS 2005. It is hard to use CppUnit. And CxxTest seems clean, simple and easy to use. It's non invasive. So I recommend CxxTest personally.
If you use VC6, there is a sample project for VC6 on the package of cxxtest-3.10.1.tar.gz.
Unfortunately, I use VS 2005, It's not so easy to integrate CxxTest in my project. I've been working on it about a noon and a night. Finally it works. My solution is just add a post build scripts to my project.
The requirement:
1. my project is a console project, and testcases(such as MyTestSuite.h) is in the same project. CxxTest cases would be run in executables. I compile and link the Cxx Tester in post build scripts.
2. the post event would call CxxTest perl script to generate code and executable to run test cases. (generated code is in runner.cpp, and the executable file to run cases is run.exe).
3. So the project has 2 main functions, one is the main output, another is in the generated code. It needs bit trick to use #ifndef ... #endif around the main function to avoid compiling error.
(PS, firstly I added PERL variable to c:/perl/bin/perl.exe and added "E:/Program Files/cxxtest" (where cxxtest is extracted) to my PATH variable, so I can invoke cxxtestgen.pl from command line directly, of course perl is installed. And I wrote my test cases in file MyTestSuite.h. Here's the Scripts in Post Build Event, attention these bold text are added based on the original compiling/linking command when I changed the project output as DLL:
rem post build for VS.Net 2005 :
echo ##############generating runner.cpp##############
cxxtestgen.pl --error-printer -o runner.cpp $(ProjectDir)/*.h
sleep 1
echo ##############compiling runner.exe##############
cl.exe /D "_UNICODE" /D "UNICODE" /I "E:/Program Files/cxxtest" /I "E:/workspace/SICExtension/SICExt" /I "include" /I"." /FD /EHsc /MT -o ../release/runner.exe runner.cpp *.cpp Nafxcw.lib Libcmt.lib /link /NODEFAULTLIB:Nafxcw.lib /NODEFAULTLIB:Libcmt.lib /LIBPATH:"lib" /PDB:"e:/workspace/SICExtension/release/runner.pdb"
../release/runner.exe
After added the post build scripts and the test suites, each time you build the project,
it will run the test, when all test cases pass, it shows like this:
1>Running 3 tests
1>setup
1>tearDown!
1>.
1>setup
1>tearDown!
1>.
1>setup
1>tearDown!
1>.OK!
When some tests fail, it shows like this:
1>Running 3 tests
1>setup
1>tearDown!
1>.
1>setup
1>tearDown!
1>.
1>setup
1>In MyTestSuite::testRegextMatch:
1>e:/workspace/SICExtension/SICExt/MyTestSuite.h:38: Error: Expected (1 == RESULT), found (1 != 0)
1>tearDown!
1>Failed 1 of 3 tests
1>Success rate: 66%
Here's MyTestSuite.h where 3 cases are added to test Addition, Multiplication, and matchRegex, ohhh, only testRegextMatch is real case for my project, it test matchRegex(string, regularExp) which match a string against regular expression.
#include <cxxtest/TestSuite.h>
#include <stdio.h>
#include <stdlib.h>
#include "SICExt.h"
class MyTestSuite : public CxxTest::TestSuite
{
private:
boost::regex reg;
public:
void setUp() {
printf("/n");
printf( "setup /n" );
reg = regex("[0-9]{4}");
}
void tearDown() { printf("tearDown!/n"); }
void testAddition( void )
{
TS_ASSERT( 1 + 1 > 1 );
TS_ASSERT_EQUALS( 1 + 1, 2 );
}
void testMultiplication( void )
{
TS_ASSERT_EQUALS( 2 * 2, 4 );
}
void testRegextMatch(void) // test regext
{
std::string regstr = "a+";
boost::regex expression(regstr);
std::string testString = "aaa";
BOOL RESULT = matchRegex(testString,expression);
TS_ASSERT_EQUALS(TRUE, RESULT);
}
};
- Post Build Event for CxxTest in Visual Studio 2005
- Visual Studio 在Post build Event 调用 signtool
- Build OWB in Visual studio 2005
- How to build an OLE DB application for SQL Server CE in Visual Studio 2005
- Visual Studio build event command line 使用方法
- Visual Studio build event command line 使用方法
- Visual Studio 的Build Event 使用
- 关于Post Build Event
- Macros for Build Commands and Properties for Visual Studio 2010
- Visual Studio 2005 All-In-One Desk Reference For Dummies
- Creating SharePoint 2010 Event Receivers in Visual Studio 2010
- Post-Build Event command line
- Post-Build Event command line
- Post-Build Event Command Line
- Post-Build Event command line
- Post-BUILD Event Command Line
- How to build mex file directly in Visual Studio 2010?
- Build Tiny C Compiler by VC in Visual Studio
- 我知道怎么治疗青春豆 大家谁有可以找我
- 1231 Sending the Request
- 嵌入式的学习
- 直线剪裁:
- Bezier曲线:
- Post Build Event for CxxTest in Visual Studio 2005
- 画圆:
- MFC的小技巧
- 完成端口(IOCP) 也可以这样用~~呵呵~ 用来充当线程之间的数据队列~
- 手机打电话log
- stk操作
- 2009年的最后一天
- 2009年总结,2010规划
- 發