6.3 KiB
googletest Home
go/gmock
Googletest is Google's C++ testing and mocking framework. Please note that there are legacy names you may encounter "gUnit" and "gMock" - these names are now merged into "googletest"
Testimonials
"I'm really enjoying trying it, and it's amazing to me how far you've taken this in C++. It's changed the way I program (and therefore changed my life ;), and one of my teams has adopted it for all/most tests (and I'm working on the other)."
-- Derek Thomson, Google Mountain View
"I started using mocks with EasyMock in Java a few years ago and found them invaluable for making unit testing as painless and effective as possible. I'm very glad (and amazed) to see you've managed to create something similar for C++. It's making the transition much more pleasant."
-- David Harkness, Google Mountain View
"I #included
gmock.h
and lived to tell the tale... Kept me from having to depend onMockBigtable
thus far, which is huge."
-- Matthew Simmons, Google NYC
"I like the approach of
EXPECT_CALL
much more than EasyMock's mock modes (record, replay). It's the best way to ensure the user will never forget to verify the expectations: do it automatically!"
-- Tiago Silverira, Google Brazil
"It's by far the best mocking library for C++, by a long-shot."
-- Joe Walnes, co-creator of jMock, Google London
Learning googletest mocking
Please see the googletest Users Guide for the combined gMock mocking documentation.
Resources for Users
- More docs:
- Interview with gMock's Creator on the Feb 2008 issue of Code Green - discusses gMock's history and philosophy.
- "Mockers of the (C++) world, delight!": TotT episode 66 - quick intro on gMock's benefits and usage
- "Mock logs better than gold": TotT episode 76 - how to test LOGs using gMock
- "Testing legacy code gently": TotT episode 84 - using mock callbacks to test legacy code without a big refactoring
- "Literate testing with matchers": TotT episode 135 - using matchers to get readable test code and readable test messages
- "Making a perfect matcher": TotT episode 139 - defining custom matchers easily
- Talks
- "Declarative C++ Testing Using DSLs" talk (6/4/2008): abstract, slides (requires Firefox) - gMock's design and implementation tricks
- "Mocks made easy in C++ and Java" talk (4/23/2008): slides, fish
- "C++ mocks made easy - an introduction to gMock" talk (1/22/2008)): slides (requires Firefox), video
- "A preview to gMock" talk (6/28/2007): PowerPoint slides
- Tools
/google/src/head/depot/google3/third_party/googletest/googlemock/scripts/generator/gmock_gen.py *your.h ClassNames*
generates mocks for the given base classes (if no class name is given, all classes in the file are emitted).
- Mocks
- mock-log.h - a sample on using gMock to create a mock class
- gmock-sample-mock-log.cc - a sample on using gMock to test LOG()s
- Folks
Resources for Contributors
- Dashboard
- gMock Design (go/gmockdesign) - the design doc
c-mock-dev
list (deprecated) - old archive, new archiveopensource-gmock
list - discussions on the development of gMock: subscribe, archive, smile!
Acknowledgments
We'd like to thank the following people for their contribution to gMock: Piotr Kaminski, Jeffrey Yasskin (who/jyasskin), Joe Walnes, Bradford Cross, Keith Ray, Craig Silverstein, Matthew Simmons (who/simmonmt), Hal Burch (who/hburch), Russ Rufer, Rushabh Doshi (who/rdoshi), Gene Volovich (who/genev), Mike Bland, Neal Norwitz (who/nnorwitz), Mark Zuber, Vadim Berman (who/vadimb).