Version 28, last updated by dascandy at Oct 07 09:42 2009 UTC
Hippo Mocks
What's new with Hippo Mocks
2009-08-09 Release version 3.1
The 3.1 release is here now. Download Hippo Mocks 3.1 here.
To be quite honest, this release is already a few months old. I've neglected updating the front page too long and forgot to add it here. My sincerest apologies for not updating it; my only excuse was getting married but that's been about two months already. Emails and direct questions from multiple people attended me to the fact that the changes between 3.0 and 3.1 were actually much desired:
- The exception buffer size was made configurable. This is a temporary fix to prevent an awkward behavior in Visual Studio from taking down your testing framework. This is (most likely) the case if you get a stack overflow on calling a function on a mock.
- Made function overload distinguishing possible again. Use ExpectCallOverload etc. to register an overloaded function.
- Running in Visual Studio with Edit&Continue has been enabled by a very ugly Microsoft Visual Studio specific hack. This means that new projects created using the wizard will not fail with very odd compiler errors but just work.
- Added most of the support for the GreenHills compiler. The only thing that doesn't work is class mocks; GreenHills appears to change their VTable layouts when objects contain data and I haven't found out how they do it. Also, their compiler costs more money than it's worth it to me to fix.
There's also a single change that nobody asked for, but that is a consequence of the GreenHills support:
- The horrible_cast is gone. It's been replaced by a function that says what I'm trying to do instead. If you used the horrible_cast, you can copy it from an older version.
2009-04-23 Release version 3.0
The 3.0 release is here already. Download Hippo Mocks 3.0 here. It contains a bug fix (reference return didn't work), lots of enhancements (exception detail, registering expected-but-wrong calls and other minor improvements) and adding a few hooks for adjusting its behaviour. It is not version 2.1 in that it has two breaking changes. The first is that the ampersand before the function name is now forbidden. The second is that objects that used to give a compile error on not being comparable with operator== now give a false value back indicating they're not the same.
2009-03-26 Release version 2.0
Today we've released the 2.0 version of Hippo Mocks. Download Hippo Mocks 2.0 here. It has much less memory leaks (probably not none yet, but we're removing them as we notice them). We've spiced up the warning resilience and it compiles warning-free on the highest warning levels of GCC (4.3.3), Visual Studio (2008, 9.0) and Comeau (4.3.10.1).
The syntax has made a few slight changes. The function ReplayAll() has been removed. It serves no purpose (and never has). VerifyAll() has been moved to the destructor so that all expectations are implicitly checked during the finalization of your test. This assumes that you have a mock repository per test. If you have one mock repository for a group of tests, you can use the VerifyAll() function and the reset() function to reuse it for another time. Loads of code have been removed to make the code that bit more readable. It's slightly over 2000 lines now.
There is a C++0x version! After a long and arduous journey, through the perils of ..... No actually, it only took about 3 hours to make it in total, and it's even much smaller than the non-0x version. This version only has about 930 lines of code for exactly what the regular version can do, and it is less limited. Due to Microsoft's refusal to support variadic templates in Visual Studio 2010, it will not be usable in Visual Studio until at least 2012 (or thereabouts). Comeau also does not yet have variadic template support in their c++0x version, so GCC remains the only compiler that supports it.
Why Hippo Mocks
Does it work for me?
Whether the syntax is the one you prefer is a personal choice, for which we have a comparison. Whether it can work on your platform is a technical issue, for which we have an overview.Why the name Hippo Mocks
In creating Hippo Mocks we took the syntax of Rhino Mocks as a guideline for a clear and readable syntax. We chose a different name from Rhino Mocks as we're not associated with Ayende (the author of ) and it would be an infringement on the name of Rhino Mocks to pretend to have something directly to do with it. On the other hand, we do have the same approach to the same problem, resulting in much the same solution. In an analogy to CppUnit with JUnit, we chose a relatable but different name.
Why create Hippo Mocks
There does not appear to be an easily usable mocking framework for C++ that allows you to instantiate derived types whilst making your test, without explicitly writing a few classes to do so. As this is prohibited by the language itself, it's understandable. It still is a much better way to do mocking and since it is technically possible (at least in Visual Studio and GCC), there should be a proper framework for doing so.
Why use Hippo Mocks
Since mocking frameworks all differ in syntax and thought patterns for use, you will find one of many to be most suitable for you, and not necessarily the one we made. Other mocking frameworks you may want to consider:
Amop
MockPP
MockitoPP
The Google mocking framework
MockItNow
M0cxx0r
Moxy
There are a few reasons why you may prefer Hippo Mocks:
- There are multiple developers maintaining it
- It is a single header file which makes including it in your project trivial
- The syntax matches the way you think about mocks, with very few compromises
- It has unit tests itself that run both on GCC (tested with at least 3.4 and 4.3) and on Visual Studio (tested with 2008 / 9.0)
- It is full featured and supports everything we have used so far when mocking, which includes a few features not found elsewhere
- Only found combined in Hippo Mocks:
- 1024 virtual functions per object (up to, that is)
- 16 arguments that are type-safely handled (or infinite, if you use the C++0x version)
- Type-safe return values
- Type-safe exceptions
- Arbitrary order specifications, with syntax limitations to prevent (and explain to you) loops in the call requirements you're trying to specify
- Callback-style replacements for the complex or unspecifiable cases
- Purely constructive syntax - if you don't need a given aspect of a call, you don't specify it.
- Single header file - no library logic, no duplicate definitions.
How to use Hippo Mocks
- Download the latest release:
Download Hippo Mocks 3.1 here
Download Hippo Mocks 3.0 here
Download Hippo Mocks 2.0 here
Download Hippo Mocks 1.0 here - If your compiler is not a known supported option, it's a very good idea to run the hippo mock test suite first. It is located in !HippoMocksTest/ and contains about a dozen cpp files, plus another header. Compile these (after adding your preferred hippomocks.h, see the next bullet) and run it. If it says that all test cases passed, you're all set. In either case, I'm very interested in your test results.
-
Copy your preferred hippomocks.h to your system or project directory. It can be any directory that is used for headers in your project. There are two options for the header:
- The c++0x version. This one is clean and simple in implementation, but only works on compilers supporting variadic templates. Practically, it only supports gcc 4.3 and newer, and only then if you explicitly enable it.
This one is located in HippoMocks0x/hippomocks.h in the release zipfile. - The usual version. This one is much less clean and contains lots of repetition, but it works on lots of different compilers and is probably what fairly recent compilers will support.
This one is located in HippoMocks/hippomocks.h in the zipfile.
- The c++0x version. This one is clean and simple in implementation, but only works on compilers supporting variadic templates. Practically, it only supports gcc 4.3 and newer, and only then if you explicitly enable it.
- For an introduction to Hippo Mocks, you can use two different sources: The tutorial and the test cases included with the release. The tutorial also explains the methodology and the construction a bit, which the tests do not do.
I'm missing this one feature that would make it so much better for me
If you're in this situation there are three things you can do, in order of amount of convincing it involves:
- Do it yourself, then contact me to convince me it's a really good idea. If I agree I'll merge it back into the source tree.
- Hire me to do it for you. This involves regular payment and getting me to/from where you are. I'm also going to expect that I can merge back the changes I make there as a way of keeping the open source up to what people expect. You need to convince me it's of general good use before I will merge it back.
- Contact me to convince me it's a superb idea. If you succeed, I'll do it without any other help and commit it into the source tree
I really like it, but I need you to come tell your story before my colleagues will accept it / for any other reason
In the same vein, I'm always open to telling the story behind Hippo Mocks or providing a compelling argument for using it. Not in the least because I'll fix your problems with it even if I don't agree with them when I do come for the talk. Just like consulting (just above), this requires some form of payment to refund my costs and time. Usually I'll make the presentations and so on for free.
Why use mocks in your tests
Should we use a mocking framework
When to use mocks
Mock roles, not objects [PDF]
Using mock objects effectively
Our opinion is that you use mocks to "fake" or hide the rest of your system in the same way you use headers to hide the knowledge of the implementation of classes. You would then also use mocks every time you use headers - IE, around the borders of each class under test. This makes the test rely solely on the behavior of the class you're testing. That means that when the test breaks, only the class under test needs to be considered.
Who made Hippo Mocks
We are Mike Looijmans and Peter Bindels, both working at Topic Automatisering. We decided that replacing functionality for the purposes of testing easily should be a base construct that is publicly available to everybody. Hence we created Hippo Mocks.
What license do you release it under?
We've decided to release it under the LGPL license. This license, in short, allows you to use it like the GPL would, with the exception that your software does not become GPLed by doing so. You are still strongly encouraged to send back changes you make.
Why do you release it for free?
There is a multitude of reasons why it is free.
On one hand there's a practical reason. If this were commercial, there would be no way to limit a trial version or a shareware version other than outright removing functionality, which makes upgrading harder and defeats the purpose of trial versions. Also, there is no way to determine if somebody used mocks to get his/her tests cleaner in order to get the product better - the final product most likely doesn't contain any mocks.
On the other hand there are a few ideological reasons. I believe that the way Hippo Mocks makes you write your tests is the way to write unit tests. It is an expressive language that allows you to say what your test should do, without obfuscating it or requiring you to type more than you should have to. I believe that software that is properly unit-tested is both easier to maintain and probably of a higher quality level than those that aren't. Because in the end I'll probably be a user of most software, I prefer that the developers of any software have the ability to use a good unit testing framework that keeps their code clean and makes it work properly and cleanly. In other words, doing this for "free" means that I get better products in the shops. It also gives me a warm fuzzy feeling inside to know that people appreciate what I'm doing.
If you do wish to do something to help Hippo Mocks (such as pay for it), you're invited to hire us to give a talk, add features for your benefit or make a donation. We also very much appreciate receiving post cards from wherever you live or any Hippo-related souvenirs. If you want to send us anything, please send it to Topic Automatisering, attn: Hippo Mocks, Eindhovenseweg 32-C, 5683 KH Best, The Netherlands.