Working on creating my own Unit Testing and Mocking framework (none of the existing C++ ones match what I want).
So far what I have seems alright. It's based on a BDD-like "Given-When-Then-Finally" format where you define a test as
Given A
- When B
-- Then C
-- Then D
-- Then E
- When F
-- Then G
- Finally H
Given I
-- Then J
Which would call the logic for:
Given A When B Then C Finally H
Given A When B Then D Finally H
Given A When B Then E Finally H
Given A When F Then G Finally H
Given I Then J
The idea is to allow for a more natural "Arrange-Act-Assert" style to tests, whilst allowing to add a Tear Down step (finally). The idea is to make it so that Tests can be nicely formatted but it's loose enough to be very flexible, whilst actual BDD tends to be too strict about things for my likings. There may need to be a step tearing down each When, like how Finally tears down the Givens, but I'm a bit conflicted on that one. Maybe if a scenario where I need that appears...
The only thing required here is the Then, if you skip the Given or When or Finally it's treated as if those steps had logic that did nothing. The test defines the requirements for the class more in programmer terms than in managerial terms (which BDD tends to do if you ask me).
Combine it with a recreation of Nunits "natural language" style Assert.That(X, Is.SomePredicate) (here rendered as AssertThat(X, ut11::Is::SomePredicate)) and I'm kinda satisfied with what I managed to squeeze out of C++11, at least for the moment. It's a lot less Macro heavy than most testing frameworks, which is pleasing. It should work fine in GCC 4.7+ (since that's what I developed and tested it with), and may work with the November CDT for 2012 since that brought the main missing feature, Variadic Templates, into play. But VS2012 is not something I've tried.
The mocking "framework" in it needs love and me to figure out a neatish way of handling it. What's there...works-ish? For now at least. Mocking in C++ is bloody tricky stuff because of the lack of reflection. Whilst there are some libraries out there, such as Google Mock, they are all too "Expectations Up Front" for my liking (Asserting the right parameters were passed comes in the Assert step, not during the Arrange or Act, which would be where Google Mock puts it).