Over a million developers have joined DZone.

Curious about Cassandra DB Unit Testing? Here's a Tip...

· Database Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database. Try it now! Brought to you in partnership with MongoDB.

If you’re curious about Cassandra DB, but don’t quite know how to run it with unit-tests, here’s a little tip for you. Below is a simplistic Scala code-snippet that will start Cassandra as an embedded service (unless it is already running) and pick up the Cassandra configs from your src/test/resources directory (you’ll want your storage-conf.xml and log4j.properties there):

Now you can just start Cassandra by calling EmbeddedCassandraService.start, and a new server process will start unless one is already running.

I found the starts of this snippet on the web, I can’t remember where, but I believe it was in the Akka source code, and I just took it and adapted it a little to work better in my workspace..

Below is the CassandraClient convenience class that I have created and that is used in the sample:


Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}