Cassandra Spy Tests

Test error cases in code that uses Cassandra.


CassandraSpy is a library that helps you:

  • Start embedded Cassandra
  • Throw exceptions for certain queries so you can test how your application handles them
  • Query embedded Cassandra

Exceptions are triggered in Cassandra server so your application code does not need to be changed and does not need to use mocks.

Cassandra-Spy is implemented as a JUnit rule but can also be used in other contexts like Cucumber scenarios.


public class IntegrationTest {

    public static CassandraSpy cassandra = new CassandraSpy();

    public void initApp() {
        String host = cassandra.getHost();
        int port = cassandra.getPort(); // started on random port
        // init app with host and port

    public void testInsertFails() throws Exception {

        app.addUser(1, "user"); // does an insert

        // assert app does the right thing

    public void testSelectFails() throws Exception {

        app.getUser(1); // does a select

        // assert app does the right thing

    public void testInsertWithValuesFails() throws Exception {
        cassandra.when(inserts("users", 2, "user2")).willThrow(writeTimeout());

        app.addUser(1, "user"); // will not fail
        app.addUser(2, "user2"); // will fail
        // ...

Also see the tests for an example with more details.


    repositories {
        maven { url '' }

    dependencies {
        compile 'org.andrejs:cassandra-spy:{version}'


The project is inspired by:

It is written in Kotlin so is usable from other JVM languages.


Apache 2.0

Cassandra Spy

Helper library to test error cases with Cassandra db

Cassandra Spy Info

⭐ Stars 10
🔗 Source Code
🕒 Last Update 2 years ago
🕒 Created 4 years ago
🐞 Open Issues 4
➗ Star-Issue Ratio 3
😎 Author ajermakovics