Unit testing (Session Exceptions)

I am unit testing Session exceptions but can’t figure out how to simulate session exceptions or how to substitute Session, SessionException classes with their mock objects.
According to the documentation, I can use the method
SimulateError(this Session session, ErrorCode errorCode, string message, bool isFatal = false) to simulate session exceptions.
The only way to get the Session instance is to ask it from the Realm instance. The problem is that we use In memory realm inside unit tests and that realm has no session (realm.SynchedSession is null).

So the question is how to unit test session exceptions?

Hi @Vardan_Sargsyan92,

As you correctly stated the Session can’t be tested using a non-synced realm. What you could do is to create a testing app in Atlas and to use that as a testing environment. From there, the unit test could use that App and some hard-coded values to generate a user to create a SyncConfiguration.
Unfortunately, this is not really possible if not by using some internal API.
What I can recommend you is to take a look at how we execute our SessionTests and specifically how we generate a fake config to create a synced realm.

If after taking a look at our tests there is something unclear then don’t hesitate to ask.


HI @Andrea_Catalini

Thank you for your answer to my question.

Now it’s clear that why I am not able to create a unit test for the synchronization exceptions and I should create an integration test instead.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.