What is the current state of BDD in C++? - c++

So I found a few older questions asking about BDD frameworks for C++. CppSpec was recommended as a BDD-style framework, but the framework is not nearly as elegant as RSpec or even googletest.
I also saw mentioning of an article detailing Unit Testing C and C++ with Ruby and RSpec which sounded really interesting. However, the article states that there are a lot of limitations with using this method with C++. Has this gotten any better? If not with Ruby, has SWIG become better at interfacing C++ and Python? Could I then attach something like Cucumber?
The last thing that occurred to me was to use googlemock together with googletest (which I'm already using some for unit testing), though it still doesn't seem as elegant or quick as using Ruby or Python BDD frameworks.
I think the key to making BDD/TDD work is that writing tests should be quick and painless. I'm trying to introduce these and other development methods at work and I may need to convince people that writing tests can be short, sweet, and easy.
Update
I just found out about Kross, which might work well because the application uses Qt and targets a Linux environment. Could this potentially be easier/better than SWIG?

Have you taken a look att Igloo?
We don't have nearly as many features as for instance googletest, but we created it with the intention that you shouldn't have to repeat yourself, and we took some inspiration from RSpec and NUnit, and tried to create something pleasant.
Disclaimer: If it's not obvious already, I'm one of the developers behind Igloo.

Related

How stable is NSubstitute?

My company is looking to standardize on an Isolation Framework. I was looking at MS Stubs (cause Moles seemed cool and I thought I would keep it in the same framework). However, Stubs is not quite ready for prime time yet (it is still a bit buggy in normal functionality).
So now I am looking at what else is out there. I have looked at Moq and Rhino mocks. While doing that, I came across the fabulous comparisons done by Richard Banks. In that he shows NSubstitute. I really like what I see there.
However, after having been burned a bit by MS Stubs, I don't want to bet on an alpha/non-production ready Isolation Framework.
So, is NSubstitute ready for prime time? Or is it still a bit buggy?
There is a discussion about this on the official NSubstitute group.
The alpha tag was originally used to indicate that the API was still subject to change. The API has now stabilised, and most of the outstanding work for a 1.0 release is documentation. You can get an indication of some other planned work (for both v1 and v2; mostly planned features) from the issue log.
We have been using NSubstitute on a major project with a team of 6 developers and are very happy with it.
Note: I work on NSubstitute, so may be a tad biased. :)
UPDATE: NSubstitute 1.0 has been released.
I've been using NSubstitute on my project and I haven't had any problems. I picked NSubstitue mainly just to try it out, because I like the syntax and how easy it is to fake an implementation due to it being loose. Since I wasn't sure if I would keep using it at the time, I put a little wrapper around it for my own little DSL, whenever I need a fake.
Also to note, I mainly develop C# on Linux with Ubuntu, Mono, and MonoDevelop and I haven't had any problems with it working under the Mono 2.6.7 runtime. You can probably use any of the 2.6.* runtimes, but I haven't tried it. The Mono 2.6.* runtime is equivalent to the .NET 3.5 Framework.
It's everything they were hoping, with their phrase from the website: It's meant to be simple, succinct and pleasant to use.
We were using Rhino Mocks but we have replaced all our mocking code with NSubstitute. It is very stable, far easier to work with, away less code required to do what you have got to do and a small, concise but effective API.
Would strongly recommend it!

What documentation (, links and advices) could you offer me to create a testing library?

I'm thinking of designing my own Test library (framework) ->in c++
I am wondering if some of you have already designed there own (and what good advices, documentation they could offer me), decided to not do that (and why), What critics (and argue) you have against differents existing testing frameworks.
I want to no more about testing framework design.
In fact I have some pretty differents things to test :
simple unit test
MVC and signal slot
data, (escpecially for audio and DSP)
performance
compatibility
"So much things ... and so few time "
No really I need to test a lot of different things.
So I checkout how is designed XUnit, and the Addison and W XUnit related book, also the Advanced Unit Testing related article on code project....
And different articles, discuss this with coworkers ...
And at the end, I want to design my own.
Why :
specific needs,
like the do it yourself way (and learn why it's done this way in existing frameworks and that I'm not a genious ... ^^)
Thank you all.
I remember having read some discussions about Cppunit 2 design on the sourceforge wiki. I'd start from here. Also, Noel Llopis explored the C++ unit-testing framework jungle.
But, you're saying you want to re-create another framework and you only have few time left. I'd suggest picking one framework fitting your need for the unit tests, see if it can be used fore your MVC and data testing. Moreover unit testing framework are not designed to run performance tests. I'd recommend following the Unix philosophy here: simple little tools that do one thing and do it well.
Learn at least one existing framwork before you implement your own. My experience is that the framework is not the problem. Learning how to write good unit tests is the hard part.
I have used several framworks through the years including CxxTest, CppUnitLite and UnitTest++. But my recommendation is Google Test together with Google Mock (Google Mock comes with a copy of Google Test bundled).

What are some good examples of open source projects developed in a test-driven fashion?

I found Open source projects with good quality tests but I wanted to ask something a bit different.
I'm having a hard time visualizing how to build production code using TDD practices, particularly for networked database-driven applications where big chunks of functionality are dependent on one or more external systems. The two main strategies I've seen discussed for accomplishing that are decoupling code from the systems in question and using mocks. However, my intuition is that doing either one properly would also be complex and error-prone.
I'd like to take a look at some real-life code that was built using test-driven development practices from the ground up. Such a project would have had to deal with such issues from very early on, and I think looking at the results would be instructive. Any examples out there, whether positive or negative?
Some testing frameworks come to mind ...
JUnit
FitNesse
RSpec
(Though of course this was BDD rather than TDD!)
Both the Ioke and Seph programming languages, as well as their implementations ikj (Ioke interpreter for the JVM), ikc (Ioke interpreter for the CLI) and whatever the Seph implementations is called, and their standard libraries were written 100% test-driven or rather behavior-driven.
Since Autofixture was created to facilitate TDD, I'm sure that the source code for the project itself was developed according.

Unit testing in C++

I've been reading a lot about Unit tests and Test Driven developemnt.
Recently, I also read java unit test code.
I however, prefer to develop in Qt. So I googled up "unit testing in c++" and found a host of information about various unit testing frameworks available for C++.
However, I could not find a reliable comparison of the the various frameworks.
So I look to the SO community to guide me through the selection of what may the "best" unit testing framework for c++.
Also, if anybody had specific comments regarding TDD in Qt (especially using Qt-Creator), then they are more than welcome.
Usually use Boost, but if you are using Qt, their QtTestLib might be the better choice.
I would recommend doctest (created by me) - it's the lightest on compile times from all the popular testing frameworks. It is also a direct competitor to Catch which is currently the most used framework - checkout the differences in the FAQ
This seems too be the same question as:
Unit testing in C++ which is actually c++ despite the URL title.
From there, they link to two more SO questions which should help:
Unit testing for C++ code - Tools and methodology
C++ unit testing framework
There is a table comparing all (?) the C++ unit test frameworks available from wikipedia.
There also is an old comparison of C++ unit test frameworks available. I do not think it has not been updated so I mention it as a complement as it's more argumented than the table. It covers, CppUnit, CppUnitLite, Boost.Test, NanoCppUnit, Unit++, CxxTest, especially it does not cover Google C++ framework.
The "xUnit" family of testing frameworks is usually pretty solid (jUnit, NUnit, etc.). I haven't used it myself, but there is a port of jUnit for C++:
http://sourceforge.net/projects/cppunit
Boost is usually a good choice, and it contains a testing framework, the Boost Test Library. I have used it for small test cases and it did what I expected, but I haven't used it extensively like in TTD.
If you want to get off the ground quickly without figuring out how to build a library, there is a single header file include solution, which supports fixtures (setup and teardown), the usual TEST() {} with CHECK_TRUE, etc.
It also has memory leak detection and performance testing capabilities.
https://gitlab.com/cppocl/unit_test_framework

Is there a cross-language TDD solution?

I want to write a simple colour management framework in C#, Java and AS3. I only want to write the unit tests once though, rather than recreating the unit tests in JUnit, FlexUnit and say NUnit.
I have in mind the idea of say an xml file that defines manipulations of "instance" and assertions based on the state of "instance" via setup, teardown and a set tests. Then to have a utility that can convert that XML into xUnit code, for an arbitrary number of xUnits. Before I start wasting time developing such a solution though, I want to make sure no similar solution already exists.
Would FIT/ Fitnesse be suitable for what you want?
FIT is an acceptance test framework rather than unit test framework, but from what you describe you would want to ensure that the three implementations have the same behavior rather than identical designs.
FIT has links to several languages
I think you are overcomplicating things... you might consider a scripting language that you can use against all 3. I know Ruby could be used to test Java via JRuby, and C# via IronRuby, but I don't know about AS3.
I have never needed to do this myself, but I imagine a dynamic language like Ruby could really let you do it without a lot of extra work.
As a side note, you could also try writing a compiler of sorts, much like FogCreek's (in)famous Wasabi language, then you could write both your code and tests in that language, and have the compiler do your work.... this of course would probably be overcomplicated, but I think it would be a lot better than attempting to define an XML test language... and potentially a lot more readable.
You could also check out Fitnesse with Slim, as Slim should be a lot more lightweight to implement for new languages (AS3). I guess it's more about acceptance/integration testing than unit testing, but it could be worth looking into.