User forums > Using Code::Blocks
Doing unit tests (cppunit)
MortenMacFly:
--- Quote from: thomas on February 25, 2006, 07:23:52 pm ---My experience with the indroduction of ISO 9000 in a large general hospital some years ago was a 50% increase in administrative work for everybody
--- End quote ---
You're so right! At my work they started to introduce quality assurancy and certification of several working tasks based on an ISO somewhat (I don't know exactly). I don't see the promised pros yet only the increase of administration as you did...
Maybe I change my mind at someday when I see any trade-off... but I'm already waiting for about a year or so...
Morten.
Ps.: Sorry for being completely off-topic meanwhile... :oops:
kfmfe04:
This is a very old thread, but in case other developers are trying to use cxxtest, I managed to get it working using this setup:
1. Create two projects - a static library project called mylib, and a console project called mylib_test
2. Make mylib_test depend on mylib via Project > Properties > Project dependencies...
3. Put my tests into the mylib_test project's include folder. eg Test_smart_ptr.hpp
4. In mylib_test, go to Project > Build options... > Pre/post build steps and add a line to Pre-build steps:
cxxtestgen.pl --gui=QtGui -o $(PROJECT_DIR)src/runner.cpp $(PROJECT_DIR)include/*.hpp
Of course, you can configure this last cxxtestgen.pl line to output just text, if you prefer.
Under this setup, the build will fail (with red in the GUI) upon failure of any unit tests.
I usually have mylib_test selected on Release and hit <F9>, change/add code, hit <F9>, etc...
In other IDEs/unit-tests, I tend to create a tests folder within the same project, but for this cxxtest/C::B combo, a separate project seems to be easier to set up.
Hope someone finds this useful.
--- Quote from: killerbot on February 25, 2006, 05:30:36 pm ---Check out C/C++ Users Journal : Edition December 2005
"Unit Testing & CxxTest"
So it's CxxTest and not cppTest, my mistake.
Comparison article :
http://www.gamesfromwithin.com/articles/0412/000061.html
--- End quote ---
kfmfe04:
Just a quick update on building with cxxtest inside C::B.
cxxtestgen.pl --gui=QtGui -o $(PROJECT_DIR)src/runner.cpp $(PROJECT_DIR)include/*.hpp
was taking too long when I got up to about 20 test files, so I cranked out a little ruby script which effectively acts as a no-maintenance Makefile. I run a for-loop over the files in my include directory, check the timestamps between my include and src directory, and generate with (inside a ruby script)
`cxxtestgen.pl --part -o #{full_cpp} #{full_hpp}`
if a rebuild is necessary, where full_cpp is a full-path to my cpp file and full_hpp to my hpp file. I don't really know ruby, but it's such an intuitive language that I was able to crank out my script in about 30 minutes (about 25 lines) - took me longest to find out that #{var} is used to escape a variable inside a shell `cmd` invocation.
For the build dependencies to work properly inside C::B, add all the *.cpp files generated.
There are a few extra lines wrapping:
`cxxtestgen.pl --gui=QtGui --root -o #{full_cpp}`
Now, when I do my pre-build from inside C::B, the ruby script only calls cxxtestgen.pl on the headers I touched so the build/link/test cycle is much, much faster than before.
============================================================
#!/usr/bin/ruby
indir = "/foobar/include"
hppnames = Dir.glob( indir + "/*.hpp" )
hppnames.each {
|hppname|
cppname = hppname.sub(".hpp",".cpp")
cppname = cppname.sub("/include","/src")
htime = File::mtime( hppname )
rebuild = true
if ( File::exists?( cppname ))
ctime = File::mtime( cppname );
rebuild = ( htime >= ctime )
end
if ( rebuild )
puts "Regenerating " + cppname
`cxxtestgen.pl --part -o #{cppname} #{hppname}`
end
}
cppname = indir.sub("/include","/src") + "/runner.cpp"
if ( !File::exists?( cppname ))
`cxxtestgen.pl --gui=QtGui --root -o #{cppname}`
end
oBFusCATed:
Hm, this cxxtest looks ugly by the way kfmfe04 is using it. Lots of unnecessary complexity.
After seeing this thread, I've decided to give a try of the TDD religion. So I've reread the http://gamesfromwithin.com/?p=50 and then about their UnitTest++ lib.
Downloaded it and setup a test project for a testbed CB plugin I'm doing at the moment.
I've added it as a separate project and added the files that I want to test from the original project to the test project, written the some tests and added a post-build step to run the test executable.
Everything works fine, except that if I modify the real project the test won't recompile and rerun.
There are two options that I have:
1. Convert the test project to target in the real project (will try it tonight)
2. Somehow make C::B to recompile the test project every time I build the real project. I've tried the project dependencies dialog, but it does not work :( The thing I need is to setup the post-build step of the real project to build my test project, but I suppose that is not possible at the moment (and never will be).
killerbot:
unittest++ works very well in CB. I have nearly finished my wiki article preparation. Will be completely finished in 3 weeks time when I have some time off.
The only issue is project dependencies in CB, but that's a general CB issue.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version