Getting started with unit testing for c++ in eclipse on Ubuntu - c++

I've recently switched to an Ubuntu os where I'm working on an important c++ project. I am using eclipse as an IDE and I was wandering what is the best way to do unit testing considering I've never done any unit testing.
Links for tutorials would be most appreciated.

I used google test for unit testing my project which is C++ based. It is easy to set up and use. Please check the below link.
http://www.codeproject.com/Articles/811934/Cplusplus-unit-test-start-guide-how-to-set-up-Goog

Related

Unit Testing framework for Embedded platform in C++?

I am working on an embedded systems project using ACE Framework and all the development is done using eclipse IDE. I am looking for a good testing framework.
Basically the project involves parsing of incoming data and I am searching for a unit testing framework which suits my project. What are my options here?
I recommend you try out Catch or doctest, which are quite similar.
Try ceedling: It is UT framework from throw the switch,
from http://www.throwtheswitch.org/ceedling

Unit Testing on Embedded C++ (ARM9)

I come from the world of Java and JUnit. I made a demonstration of Hudson and all what I achieve there with JUnit among other things. I would like to do the same with C++ code on an embedded device but can't find where to start.
THe project is compiled with iccarm.exe (IAR compiler) Right now the output is converted into an image file using romutil.exe to be flashed to the ARM9 board.
I tried to follow this tutorial: http://netbeans.org/kb/docs/cnd/c-unit-test.html but I'm having issues trying to figure out how to port it to my case.
Can I run unit tests on the C++ code outside of the device? (i.e. for doing it with Hudson to gather reports and so on)
Can I turn the output into an exe? (looks like Netbeans expects it to be)
What's the most appropriate unit framework for my case? (CppUnit, CUnit, etc)
Any help/direction is more than welcome.
1) You could build a cross-compiler, and then instead of using iccarm.exe, use the cross compiler. There are lots of tutorials on the net how to build a cross compiler using gcc. Then instead of building for the target (using cross compiler) build for your host using normal compiler.
3) Whatever you like. cppunit, google unit tests, etc

Optimal Eclipse CDT (C++) experience in March of 2010

I am a student who will be using C++ next quarter. I really enjoyed using the Galileo release of Eclipse with Java and I would like to continue using Eclipse for for C++ development.
I am now experimenting with C++ development on Eclipse. I am running Eclipse 3.5 SR2 with CDT 6.02. My operating system is Windows 7 and I have installed MinGW-5.1.6. Version 6.3 of GDB is installed.
I have it compiling and stepping through code. However, I have the suspicion that I'm just crawling along and have yet to "shift the car out of first gear". I've spent about a week poking around on the Web to learn what constitutes and "optimal" C++ Eclipse experience. In particular, I'm interested in round-tripping with UML and unit testing.
My exploration of the Web became an archeological dig. I turned up how-to articles from 2003, alternative MinGW distros, references to plugins, dead-links, more references to plugins, passionate discussions on gdb bugs, and more references to plugins.
I no longer have any idea what might constitute an optimal C++ Eclipse environment. Would members of the community like to weigh-in on what they consider to be the current optimal experience for C++ development using Eclipse?
CDT 7.0 (out now in June) will have a preview of Codan, a static analysis framework for C/C++. It will highlight logic errors for you in "realtime", i.e. without having to wait for compilation. (It doesn't have very many checkers at the moment, but the number is growing, and you can also implement checkers of your own.)
CDT 7.0 also features a new debugger contributed by Nokia (called "EDC"), which allows debugging without relying on 3rd party tools such as gdb. This will also allow debugging of Visual Studio binaries, something which previously has been impossible.
The "Open Type" and "Open Resource" commands of CDT (and JDT also, BTW) is something I always miss when I have to do stuff in Visual Studio. Being able to locate any type by incrementally typing a part of its name is very practical, and Visual Studio has nothing close to it.
Integration with unit-testing is still missing, though. Not sure why that hasn't caught on.
Here is what I ended up with for a C++ development environment on Windows 7.
Compiler & libraries
Nuwen MinGW Distro.
It includes the Boost libraries which are necessary for the unit testing framework.
A big thanks to Stephan T. Lavavej for making this distribution available.
Debugger
The GNU debugger as built for Windows.
I copied the file gdb.exe into my C:\MinGW\bin folder and it worked well.
Thanks for Equation Solution for providing win32 and win64 binaries of the GDB executable.
IDE
Eclipse IDE for C/C++ Developers.
Unit testing framework
CUTE (C++ Automated Unit Testing Easier).
Download the Eclipse plug-in using Eclipse’s software installation . Add this URL to “Available Software Sites”: http://ifs.hsr.ch/cute/updatesite.
The CUTE Website has excellent installation and usage instructions.
I failed to find a round-trip modeling tool that was useful to me. Exploring free UML tools was like wandering through a city that had been bombed. Dozens of projects stood in various states of usability. Some projects were clearly active, some were clearly abandoned, but most were somewhere in between. Visio continues to be my pragmatic choice for creating UML models.
Seeing as none of the C++ gods here on SO have weighed in...
My last experience with CDT was about 1 year ago. I too love eclipse for Java, and while CDT "did the job", I didn't feel like it did it any better than Code::Blocks which I used for cross platform development.
Eclipse does have access to UMLet which is my favorite UML tool as it uses a very simple scripting language instead of the 'mouse-click-drag-double-click-type' hell that most UML applications turn out to be. However, UMLet can also be used as a standalone application which makes tucking it into eclipse accomplish little more than wasting screen real-estate.
In the end, I really don't think you are going to find many professionals developing in CDT.
On the linux side you are going to find developers using what they wish to use (Anjuta, Code::Blocks, Dev-C++, kdeveloper, EMACS, vim, etc.)
On the Windows side you'll find Visual Studio overwhelmingly followed by the IDE's above that happen to be cross platform.
In the end, if I HAD to develop in Eclipse; I would use CDT, UMLet, and Subclipse. After having done that I would probably long for my TortoiseSVN, Visual Studio, Code::Blocks, and UMLet standalone.
As far as any automated unit testing goes? Don't know, write my tests by hand. Hope that helps.

MSTest for huge legacy codebase

we have a huge codebase with about 1000k lines of native/unmanaged legacy c++ - code and we are going to provide the code with unit tests and MSTest would fit perfectly in our current development environment (TFS, VS 2010, ...). I know that MSTest is orginally meant to test managed code but its also possible to write unit tests for unmanaged sc.
Are there any (later) drawbacks on the usage of MSTest for unmanaged code? Does anyone have any experience on this?
The second opinion would be using Google.Test, but I would have to write a Visual Studio add-in to integrate the gtest framework in our environment.
Thanks in advance!
I would not recommend MSTest for managed testing. See here for my experiences. However if you do insist I would say a really good way to test you legacy code would be use PInvoke interop to your c++ code.
I would recommend googletest anyway. I think they will also gladly accept your VS integration and include it in the next release, provided the patch has reasonable quality.
Oh, and you can use another great Google project then, gmock.
I use the Boost.Test framework to test my C++ code in Visual Studio without any issues. You need to create a test project (a console-mode EXE) that contains your tests which your main project can depend on. Using the Visual Studio 'post build' step you can run the tests automatically.

Setting up Mobile JUnit tests to run under JUnit

I'm using Mobile JUnit, released by Sony Ericsson for unit testing for my J2ME project. I read in the documentation that one can run the tests under regular junit with the help of a few wrapper classes. The documentation, in fact, recommends that you do this if you want to generate reports for CI builds, etc. which is exactly what I want.
Unfortunately, the documentation is a little terse on how to do this. Has anyone had any luck with this aspect of Mobile JUnit?
What I did (and I'm not saying this is necessarily a good idea in general, but it worked in my specific case) was to separate the the code base into a library and the UI. The library didn't include an J2ME specific stuff in it and it didn't include anything that J2SE had the J2ME didn't. As a result, you could check it out in NetBeans as a J2SE project and it would compile. Then I wrote JUnit tests in the J2SE context. This doesn't help test the UI, but it made it very easy to test the library.
It sounds like you found a more complete solution that tests both. Can you elaborate on what microemulator you used?