This is the way to go for unit tests. Using QuorumPeerMain is only for Multi Server (Clustered) Zookeeper.
– sourcedelicaSep 11 '12 at 23:50

2

this is a far cleaner solution than the accepted answer.
– Adam KaplanMar 25 '13 at 18:40

This is useful in the context of BeforeClass, but shutting this down between tests (to clean out the nodes, for example) is non-trivial -- I gave up and switched to a Curator-based solution. (thread.stop/interrupt in After would stop the JUnitRunner)
– Rick MoritzMay 11 '16 at 12:21

Any chance you know how to set this up in a C++ project?
– serupNov 14 '16 at 12:16

Netfix opensourced Curator a framework to make use of Zookeeper even more convenient. It has build in test server class. Just add this test dependency to your project descriptor be it maven, gradle or else: