New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit test with robolectric #252
Comments
I was able to resolve it. Something is starting ActiveAndroid before my test, so I do a ActiveAndroid.dispose() before initializing it. |
@LucioC hey, what did you do to make it work? |
@LucioC Do you have a repo with this example? |
@IlyaEremin @hdavidzhu hello guys, this was an old issue I had. My problem was that my application class was calling ActiveAndroid initialization, and for some reason that I don't remember, this was not ok for my tests, so I had to dispose and reinitialize. I think I was also able to create an application test class used by robolectric instead of the default one from my application, and do the initialization there instead of repeating it for each case. Because this is an older version I'm not sure if things changed. Do you have the same log error? |
@LucioC for me, just curious to see how to actually implement ActiveAndroid unit tests. The |
@hdavidzhu oh right. The only way to mitigate this coupling is using Robolectric. Their default project samples should help you with the default config, that should work with ActiveAndroid. |
@LucioC Thanks for the input. I'll check out Roboelectric. |
Hello guys, I tried to search this problem but was not yet able to find how to do this.
I just want to unit test a model. I'm using android studio (with gradle) + robolectric 2.3.
I tried the following:
Configuration config = new Configuration.Builder(Robolectric.application)
.addModelClass(MyModel.class)
.setDatabaseName(null)
.create();
ActiveAndroid.initialize(config);
And when I do a new in my model, it raises an exception:
java.lang.NullPointerException
at com.activeandroid.Model.(Model.java:55)
Model.java 54 to 55 has:
mTableInfo = Cache.getTableInfo(getClass());
idName = mTableInfo.getIdName();
So it seems the cache don't have the table info for that class. I tried to do a Cache.initialize(config) also but I still got the same error.
What should I do to make it work?
Thank you.
The text was updated successfully, but these errors were encountered: