Testing DAOs (which connect to locally running Cassandra)


How can I test a DAO which is being injected in one of my services?
I would like to actually connect to a running Cassandra and run my integration tests.

  lazy val server = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(false)) { ctx =>
    new XApplication(ctx) with LocalServiceLocator
  val xDao = server.application.xDao

I try to do the above but I get the runtime error - No contact points for [cas_native]
I’ve even tried to include an application-test.conf file in my /test/resources folder, but I don’t understand where to set this cas_native value.

Please let me know if there is a way to test a DAO.

1 Like

In you test setup you are setting indication that cassandra should not be used:
Set it to true

Thanks Alan, but if I set it to true, it starts its own instance of Cassandra, whereas I want to connect to the instance running locally on my machine, which we specify in the build.sbt file (using the cas_native setting).

@mmwaikar i do not believe it is possible to use external cassandra in unit testing.
Did not try it personally but I know that external http services can not be used in unit testing so would conclude it applies also on external cassandra.
For me it is not logical to use external cassandra for unit testing because unit tests should be isolated.
If you require cassandra data preparation you should do it also as part of a unit test.