Best practice in writing test cases

Hello!

Developing app using Couchbase and Node.js we bring our usual practice cover database related logic with test cases.
My previous sql experience force me to go this way:

  1. clean all old data(get all keys from view, delete records)
  2. insert new data from e.g. file
  3. call keys from view with stale: ‘false’ to force indexing

This is procedures which I was planning perform before any test. Unfortunately, time to time I getting stale data nomatter of stale: false.

So I was wondering, how experts are writing test cases for Couchbase?

Hey serggulko,

In the case of .stale(UPDATE_BEFORE), you should be getting data that is up to date for that point in time. Keep in mind if you perform asynchronous inserts that you’re data might not actually have reached the server yet, make sure all insertion operations complete successfully before attempting to perform a view read. Note also that the Node.js client comes with a built in mock system that allows you to locally mock the behaviour of the client quite closely to what you would expect from a real server. Tests are an excellent use for this (and the main reason for it).

Cheers, Brett

Hello Brett!

Thanks for answer! I was thinking about start using more for second layer(above pure DAO objects).
Looks like I need load all design documents into mock instance before start using it(we have couple of views).
Can you show me how this can be done from node.js?

Hey seggulko,

The mock models the bucket management api just the same as the default buckets. This means you can simply do bucket.manager().upsertDesignDocument(...) as you would there!

Cheers, Brett

Sorry, man, I just found answer in your test cases:)

Brave developers never read documentation and not re-viewing tests code:)