Is there any way to generate automated unit test cases for c++ code written using VS2005. I do some basic R&D and found that there is a support for automated testing in VS2005 but its only for Managed Code, so i am looking for something specific to:
"Automatic generation of Test cases of Native C++ Code"
It doesn't matter whether its a plug-in that works with VS2005 or any standalone application. But it is preferred to have some plug-in sort of solution.
I can't tell if you are asking about a unit testing framework (if yes, try cppUnit), or if you really want tests code-generated. If the latter, I imagine the answer is no. Usually a capability like that is linked to reflection and/or built-in design-by-contract capabilities (e.g Eiffel or C# with .net 4.0).
Related
I have a small library that is ported to different platforms (win, os x, ios, android) that I am using in some small personal utilities and I am starting to look into testing more thoroughly.
Right now, I am using NUnit to test the windows version, with test cases written in c#. The setup just basically loads the dll and the test cases make various calls to the library. I want to duplicate this testing on the other platforms. I know there are other xUnit type frameworks to accomplish this on the other platforms, JUnit etc., but I would rather not have to rewrite the test cases for each platform.
Is there a recommended way to have one set of test cases and just point them to one of the libraries to run against that platform?
I still consider myself a novice programmer, so apologies if it's not possible and the question is naive.
Thanks
Due to the nature of unit testing(testing individual procedures or functions rather than overall program functionality as in blackbox testing ), and different languages supports different language specific features, there cannot exist a universal unit testing framework that supports all programming languages (in your case, Java, C#, Objective-C ). That's why we have xUnit framework for different languages.
Even if someone creates such framework, it would not be possible to properly test functions that uses language specific features.
There are several major unit tests frameworks, but as far as I know all of them needs to process the source code in some way.
For example, I am using cxxunit, and it requires the unit tests to be processed using some python script. The problem with this is that it increases the build time.
Does anyone know of a unit testing framework for C++ code that doesn't preprocess the unit tests code?
PS: I need it for linux, but it is ok if it is multi platform.
You could use Boost.Test. I've had good experiences with it. It does not require any special preprocessing.
You could use google test framework. You need just build library source code one time. Then you can create your tests as .cpp files, then compile and link them with gtest and needed project libraries as ordinary c++ sources.
Besides that, it is multiplatform.
I'm happy with googletest.
CPPUnit is my personal choice at the moment, and is in plain C++.
I've been using TestDog. You construct your tests using the code to test and it produces HTML output summaries.
I'd recommend considering Andrew Marlow's FRUCTOSE http://fructose.sourceforge.net/ in your evaluation too... he's a very thorough and professional developer who compared existing offers carefully before crafting his own. See also an ACCU article disucssing the library: http://accu.org/index.php/journals/1305
I want to know if anyone of you guys use TDD in your c++ projects and how it performs compared to managed languages like C# and Java.
And what frameworks you guys are using to automate tests on c++ projects?
Two useful C++ test frameworks that don't seem to have been mentioned yet are Boost test and Google Test.
Test Driven Development is possible in any language. You need the right testing tools and methodologies for the language, and may possibly need a custom testing infrastructure for your project.
I have found CppUnit (at least 1.x) to be a very poor framework -- it seems to use Java/C# idioms in a C++ language and does not have support for STL constructs.
If you want a good example of Test Driven Development (in C), look at the Wine project -- http://test.winehq.org/data/ shows their test results across the different versions of Windows, Wine and the different commits into the Wine repository. They have their own custom test infrastructure.
I recently moved from a C# project that was developed using TDD to a project that is using C++. I was dreading it quite a bit, but I find that doing C++ with TDD is a lot more enjoyable and the code is more robust than I remember from past (non-TDD) experiences with C++.
We are using Google Test. It is not as easy to use as NUnit/MbUnit, but it seems to work pretty well. There is also a Google mocking framework http://code.google.com/p/googlemock , but I have not been using that yet.
Does anyone know of a C++ unit-testing framework (e.g. CppUnit, Google Test, etc.) that can be used to write tests on z/OS?
I do most of my development on Windows using the Dignus C++ compiler, which you can use as a cross-compiler and generate object code to run on z/OS. I tried writing a sample test using Google Test, but the compiler could not compile/link the Google Test code. Google Test does not claim to support z/OS, so this was expected. But, it was worth a try!
Thanks so much for any responses this!
Try CPP Unit Lite (by CppUnit's author). It uses fairly straightforward C++ code, there's a good chance it'll work on z/OS's compiler.
I know I'm late to the party here but for anybody interested in C++ testing frameworks on z/OS I highly recommend the Catch framework which IMO easily surpasses all other C++ testing frameworks I've used. I've been using it on z/OS for about 6 months and it's a breath of fresh air. It's very easy and intuitive to use and has support for Behavior Driven Development (BDD) style tests which is a contemporary way of writing test cases.
It's header only and doesn't rely on any C++11 features which is common pitfall when trying to build modern libraries/frameworks on z/OS as the C++ compiler has limited C++11 support.
The only nit I can think of is compiles take a while because it's a header only library. But nowhere near as long as boost.
Perhaps you could open a bug report for Google Test and see if they fix it? There is probably an ASCII dependency in the code somewhere that caused the test code compile to fail. Could you dig into the error message that the IBM compiler produced?
How effective is the CXX test framework, given that you are writing unit test cases around the code that you have written. Any bug in the code might as well get translated into a bug in the unit test code as well? Isn't it something like two negatives make a positive?
Also, the time and effort spent on CXX is at least equal to if not more than the coding effort.
Need your thoughts on this since I'm not in favor of this framework being used in my project and am looking for strong points to oppose it.
On the other hand, if you think it's beneficial, please do enlighten me :).
Google offers a fantastic C++ testing framework that I have used... I never used any other C++ testing framework, and had limited experience with Junit, and I was able to pick this up very quickly, as the documentation is good. It's important to use a good testing framework, because testing is too important to give up on because of frustration with the framework. Here is a link:
http://code.google.com/p/googletest/
Hope this helps!
CXX is not very active, and writing unit test generally involves a lot of efforts. But when the first refactoring comes in, you're very grateful of the spent effort.
I've used Boost.Test & CPPUNIT. I would prefer a little bit Boost.Test, but yes, you have to write your own projects, files etc.
If you know a tool to generate your skeleton from your code, I'm all ears. :)
I would suggest that you give a try to Boost.Test and CPPUNIT. If you think there are better it will give you good rounds to oppose CXXUNIT as you will propose alternatives.
I am using cxxtest. Regressive testing is an expensive task that we only use to validate our software libraries - which provide a platform independent layer for our apps. This is to ensure that all changes will not affect the stability of the code since so many apps and projects and dependent on them.
We couple cxxtest with coverage analysis to ensure that test coverage is sufficient and also with CruiseControl to automate it.
But we do not do this for apps. Too much effort.
Building a test app is just as difficult as writing the whole library itself. I agree that you will need to work out whether it is worth your while.
I think Joel has something to say about this too:
http://www.joelonsoftware.com/items/2009/01/31.html
I prefer header-only test frameworks, here are two of them: TUT and Catch . I used TUT before in several projects, and found Catch not long ago.
1) TUT -- C++ Template Unit Test Framework
TUT is a small and portable unit test framework for C++.
TUT is very portable, no matter what compiler or OS you use.
TUT consists of header files only. No libraries required, deployment has never been easier.
Custom reporter interface allows to integrate TUT with virtually any IDE or tool in the world.
Support for multi-process testing (testing deadlocks and timeouts is under way).
TUT is free and distributed under a BSD-like license.
Tests are organised into named test groups.
Regression (all tests in the application), one-group or one-test execution.
Pure C++, no macros!
2) Catch -- A modern, C++-native, header-only, framework for unit-tests, TDD and BDD
What's the Catch?
Catch stands for C++ Automated Test Cases in Headers and is a
multi-paradigm automated test framework for C++ and Objective-C (and,
maybe, C). It is implemented entirely in a set of header files, but is
packaged up as a single header for extra convenience.