What are you using to unit test your C++ code? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 months ago.
Improve this question
I'm looking into some possible options for unit testing C++ classes.
So, short and to the point, what are you using?

I'm using cppunit. It is a pretty good port of the iconic JUnit to c++.

UnitTest++. In the past I used Boost Test, which is also pretty good, but I ran across a problem where boost test wanted an operator<< defined and it wouldn't accept my overloaded operator<<. UnitTest++ didn't flinch a bit.

I'm using Google Test

CxxTest, which runs a Perl script as a preprocessor to detect all methods named test*. It's pretty easy to work with, since Perl does all the suite/case registration for you.

Boost.Test. I use boost anyway, might as well use its test library as well rather than yet another different library.

Simple console applications that link the lib / DLL, and use assert statements.
It fits my main requirements: easy to set up, and when an error occurs you can immediately break into the debugger.
To run an individual test repeatedly, the call to the routine is (temporary) copied to the top.
It has some shortcomings, though: First, you don't have an automatic visual verification which tests did run, but that can be fixed with a print statement. You don't get a list of tests that failed. Beyond that, compared to any environment supporting reflection, the added value of unit test frameworks seems a bit low to me. And better these than no unit tests at all.

Have a look at CUnitWin32. It includes an example.

Related

Is there a *free* QT UI testing framework available? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am looking for a free QT UI testing tool for Windows. I have unit tests for my backend modules using boost::Test. However, the UI has more potential to malfunction and I would also like to test this.
The testing frameworks that I found using the search function on Stackoverflow only involve a few frameworks - and those do cost. Also, it should be usable with an LGPL project.
Is there any free way to do it?
Testing / Troubleshooting User Interfaces is a very tough process.
Classic unit-test frameowrks (QTest, boost, gtest) are usefull for testing non-interactive modules, classes, functions.
When inputs are required, things become much complicated.
You could choose a "mocking" framework such as gmock to "simulate" a user input.
But if your GUI application has many windows, dialog-boxes, gui elements it might become a real pain in the neck.
There is a second approach that I recommend.
I spent years developping applications with Qt. My first applications did not respect any MVC model.
The debugging and the code tuning was very painfull.
I also made an effort to separate the logic from the user-interface as much as possible.
Just like the MVC model of Qt (QAbstractItemModel).
This way, you're able to test your models in regular unit-tests frameworks.
You can extend this logic to all of your gui components.
Finally, you'll still have to perform "human tests" to troubleshoot your application.
But this is a normal phase in the development process.
There's only a human resource that could use your software, click anywhere in the windows, dialog-boxes, do weird things etc
That's the best way to find out unbelievable GUI bugs !
Not a unit-test can find them out.
A developper cannot reproduce the behavior of the person that will use your software.
Because we unconsciously know where bugs may occur...and thus, we often don't click where it's not recommended...
Think about it.
Z.

provide unit-testing for c++ code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to provide unit tests for an application written in c++, this is a very big application and content many sources (.h, .cpp) , actually I don't know where to start? How to process? ...
So any help is more than welcome.
Thanks
Did you upset someone? Given there are no unit tests, the chances of the code being written to be testable range from slim to absolutely none.
Without seeing the code and spending several weeks if not months with it no one can give you more than a general strategy.
There will be some functions you can write unit tests for. Those will be ones where the arguments are easy to generate, they do very few things, one thing would be nice, and they don't have side effects. Attack these first, get them out of the way.
There will be others which nearly fit the above. Now you'll be tempted to re-engineer them a bit so they do, don't do it until you have some sort of test. Write tests for the bits you can. Write integration tests where you can't.
So the basic idea is to get as many tests as you can before you start changing the code, so you can test it and then, to make the smallest change possible to make the code better and write the tests first!
There are a fair few patterns or strategies you can use (get a good book on re-factoring legacy code), start with the simple ones.
Prepare for dismay, hard work and rework, but the best piece of advice I can give is don't try to take short cuts, after all that's what the chuffer who left you with this did isn't it?
Grab a good test framework.
I have used google test a lot with my last company, and it was pretty good, though there are likely better around.
Reading:
http://code.google.com/p/googletest/
Comparison of c++ unit test frameworks

Looking for introduction of nmake & makefile structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am looking for some basic information regarding makefile structure. Any pointers will be highly appreciated. Thanks.
Official NMAKE documentation.
There are several other types of build systems that use "makefiles". Several of the other answers here are pointing you to these other systems. They all implement the same basic ideas, but the capabilities and syntax vary, sometimes in subtle ways. If you need to learn how to use NMAKE (which is the one you mentioned in the title), and you read GNU make documentation, you're likely to get confused.
The best help I think I can give anyone desiring to learn how to write their own makefiles is:
DON'T DO IT!!!
Use a makefile generator. There's a lot out there. One of the best I've seen is CMake but there's also automake/autoconf/all that.
You can also use a totally different build system like Ant (but that's by far the only option in this category).
Make actually kind of sucks. I haven't touched one in 10 years. Put your development effort where it will do the most good, in your code.
For very quick start (if you haven't yet tried) - read this, very simple.
If you want start writing makefiles in couple hours - this one.
To be a monster in makefiles use official, commonly you need this as reference book.
You may want to have a look at the Autobook
I agree with most earlier responders: don't continue to be dependent on NMake, use newer tools. Ant, MSBuild, Maven, Scons, GNU/autotools, etc. But, if you really want to learn more about NMake, check out the Microsoft Rotor (SSCLI) source distro, it includes the source to NMake, at least a hacked-up snapshot needed to bootstrap Rotor's build. And for better examples of Nmakefiles, look in early Win32 SDKs, and later OS/2 SDKs, that was the heydey of complex Nmakefiles.

What are some small, fast and lightweight open source applications (µTorrent -esque)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Possible duplicate
What is the best open source example of a lightweight
Windows Application?
µTorrent is a small bit-torrent client, a really small one. It doesn't come with an installer, just a exe, you drop in your PATH somewhere. It's super lightweight and yet feature rich. Plus it is the work of one man. It's also closed-source.
Many people have been curious about how it has been written, and there are hints here and there about a custom library etc. But the question is, are there any programs with attributes like µTorrent that are available with source code--attributes like speed, small size, awesomeness.
Possible related question (/questions/9603/what-is-some-great-source-code-to-read), but think smaller than something like the Linux kernel.
Clarification: I don't want examples of bit-torrent source code, but anything which is used by tons of people (validation of awesomeness) and also fast, small and awesome!
I think you should take a look at Notepad++ if you want to see a feature-rich low-consumption of power software :)
Netcat
It's the program that started all of the curiousity behind networks and how things WORK.
Everyone's looked at this source code.
rTorrent is a lightweight, feature-rich, console-only open-source torrent client.
I like Frhed, a simple open-source Windows hex editor.
FRESHMEAT is a great place to start. There are lots of small open source programs available that you can study.
Examples:
XML-RPC specification.C implementation for Python. Its easy to learn and its fun.
Heapq [\Lib\heapq.py] , xml-rpc [\Lib\xmlrpc] and lots of other codes in Python library are very well written.

Are there any good open source BDD tools for C/C++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I love the Ruby RSpec BDD development style. Are there any good tools for doing this with C/C++?
cspec is for C. Presumably it will work with C++. There is a list of tools for various languages on the Behavior Driven Development Wikipedia page.
It seems you can test your C code using Ruby and RSpec using swig to generate wrappers! See Ben Mabey's post here:
http://benmabey.com/2007/09/09/bdd-your-c.html
I've tried that example out and it worked for me. I'm not sure if anyone has taken it any further.
The original link (CppSpec) is dead, but it is still accessible at the Internet Archive at CppSpec.
And as #VickyChijwani already mentioned, there's a copy of the project at Github - tpuronen/cppspec
Igloo is one I'm looking forward to try some time
Since an RSpec like framework was requested, I'd like to add the recent igloo.
Though originally aiming at Context/Spec syntax, it also supports Describe/It syntax. There isn't much noise in setting the test runner and test fixtures up like in those C-based frameworks. It even feels better to look at than CppSpec. They achieve this through use of decent templating mechanics.
Try CBehave! It is an RSpec-like BDD framework that uses given/when/then macros. Example:
FEATURE(1, "strstr")
SCENARIO("The strstr finds the first occurrence of the substring in the source string")
GIVEN("A source string: [Lionel Messi is a great football player]")
char *str = "Lionel Messi is a great football player";
GIVEN_END
WHEN("we use strstr to find the first occurrence of [football]")
char *p = strstr(str, "football");
WHEN_END
THEN("We should get the string: [football player]")
SHOULD_STR_EQUAL(p, "football player");
THEN_END
SCENARIO_END
FEATURE_END