9

I recently setup a new project that is using Spring-Data-Couchbase and I am completely stumped on how I should approach unit and integration testing here.

Typically with JPA I can mock out my Repository somehow (assuming this is similar for couchbase with Spring) and this is okay for unit testing, but normally for JPA I wire up an in memory database and have a full integration testing suite. Is there any way to do this with couchbase?

Also if you don't mind mentioning any tips here as this is my first major NoSQL project :) Thanks!

Matthew Fontana
  • 3,790
  • 2
  • 30
  • 50

1 Answers1

3

Couchbase does not run in-memory unfortunately. For unit testing you would have to mock Couchbase's API. There is a CouchbaseMock project to facilitate that: https://github.com/couchbase/CouchbaseMock

There is also the possibility to use a runner prior to launching your test. There is probably a maven plugin that would allow you to run Couchbase or a Couchbase Docker image.

Laurent Doguin
  • 483
  • 2
  • 4
  • 1
    Note that CouchbaseMock is more of a project than a product. We at Couchbase use it for focused testing of our own, but we ultimately test on the real server too. It may not have all of the features. Ping us if there's something you'd like to see though, as we have some other components too. – Matt Ingenthron Jul 11 '16 at 18:46
  • @MattIngenthron Still working getting a full handle on how the tool works. Would you happen to have a sample or simple reference project where I might be able to check out the implementation? – Matthew Fontana Jul 12 '16 at 02:15
  • Have a look at gocb (https://github.com/couchbase/gocb) or the use in the python client– https://github.com/couchbase/couchbase-python-client/blob/master/couchbase/tests/base.py#L113 and https://github.com/couchbase/couchbase-python-client/blob/master/couchbase/mockserver.py – Matt Ingenthron Jul 12 '16 at 23:45
  • 2
    Regarding CouchbaseMock, you can also have a look at its own tests: https://github.com/couchbase/CouchbaseMock/blob/master/src/test/java/org/couchbase/mock/client/ClientBaseTest.java - which shows how the mock is instantiated and how the (old) Java SDK is connected to it! – Mark Nunberg Jul 12 '16 at 23:52
  • @MarkNunberg the link `https://github.com/couchbase/CouchbaseMock/blob/master/src/test/java/org/couchbase/mock/client/ClientBaseTest.java` is broken maybe this one is good: https://github.com/couchbase/CouchbaseMock/blob/master/src/test/java/com/couchbase/mock/clientv2/ClientTest.java – Jas Oct 01 '17 at 07:55
  • Looks like the last activity on this thread was about 2 years ago - has anyone developed an in-memory couchbase database for spring-boot integration tests since then? – SnoopDougg Nov 21 '19 at 16:40
  • 1
    I guess your best bet it to use the test-container project that should allow you to run Couchbase during your unit tests. See https://www.testcontainers.org/ – Laurent Doguin Nov 22 '19 at 17:29