Test Helpers

We use a set of helpers to make testing easier:

  • Mockito to mock objects (see Testing
  • Custom annotations: @UnitTest, @IntegrationTest and @PerformanceTest
  • Class KeepTestUtils: retrieve test specific sources
  • Classes TestSubscriberGeneric, TestSubscriberJson for Assertions when extending AbstractAsycDomino

Use of TestSubscriberJson

As example for the whole set of TestSubscribers. The TestSubscriber can be used to expect success or error for the specific function under test. Expected outcomes are added fluently to the test subscriber. Not each combination makes sense.

TestSubscriberJson subscriber = new TestSubscriberJson();

Testing failure

When we expect failure we have 3 methods to indicate this:


Expectation is that the code under test will call the onError() function and not onComplete() without further specifying why. Test fails if onComplete() runs


Expectation that onError() gets called with a specific error class. Test fails if a different Error is raised or onComplete() runs

subscriber.errorMessage("A specific error message")

Expectation that onError() is called and the Error has the specified message. Fails if the message is different or onComplete() runs

Testing success

There are various switches to test success. By default a TestSubscriber expects onComplete() to run and not onError()


Expect exactly 7 calls to onNext() and one call to onComplete(), will fail with less or more calls


Expect two or more calls to onNext() and one call to onComplete(), will fail with less calls. Typical use with 1 to ensure at least one result is returned


Expect zero, one or two calls to onNext() and one call to onComplete(), will fail with more calls


WHen set a call to onNext() can be an empty object {}. If not set onNext("{}") fails


Expect every call to onNext() contains a JSON element with the given field names, no assertion on data type is made


Adds expeced JSON objects for the first and second call to onNext(). Fails if other values arrive. Exact behavior can be tuned using additional methods:


Ignore additional fields returned in a onNext() call. Just check that fields specified in addFieldsToExist() and/or addexpectedValue() are present


Pass test even if some fields in actual are missing