Backendless Support
 
Not a Problem

Android Mockito Unit Test

I'm trying to create a unit test using Mockito for my model that calls Backendless API. In my constructor, I execute the code below. The problem is that the context is null, so it results to java.lang.IllegalArgumentException: Context cannot be null.. Is there a better approach on how to skip the initApp when I'm running my unit test?

  1. Backendless.initApp(

    context,

    BuildConfig.APPLICATION_ID,

    BuildConfig.BACKENDLESS_SECRET_KEY,

    BuildConfig.BACKENDLESS_VERSION);

Leave a Comment

Comments (2)

photo
1

Hi Jan Paolo,

In Android environment you have to always specify a default context to the initApp method. For example, you can try the following approach to retrieve it in your tests: http://stackoverflow.com/a/5114361/1813669

photo
1

Hi Sergey,

My approach in creating the unit test is wrong. I'm doing the right thing now :)

Thanks!