-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
ISSUE - Unit test Problem (librealm-jni.so) #3808
Comments
The only way to work around it for now is set |
zaki50, would you discribe, how can I do this by reflecting? I have such problem. I just had to add RealmCore.loadLibrary(this) in my application class before calling Realm.init(this), yes? |
See also this example: https://github.com/realm/realm-java/tree/master/examples/unitTestExample |
@zaki50, i set |
Please take a look at robolectric/robolectric#1389 |
I created this project : |
Ah, you should create a package named
|
I'm getting this Exception when my test is running:
I did my method setUp() like here https://github.com/realm/realm-java/blob/master/examples/unitTestExample/src/test/java/io/realm/examples/unittesting/ExampleActivityTest.java but Realm.init(Context context) in my Application.class is running and I'm gettin this Exception. My test class:
|
Since you mocked everything, no need to call |
I ran into the same / similar issue. After upgrading to Realm 2.x, a lot of robolectic tests failed. The root cause was the Since I didn't want to touch any of the tests, I ended up using reflection to make Thoughts on this approach? Here is the code snippet to fake init Realm.
|
@pouyabs5 @nikiJava Did suggestion by @thorbenprimke help you? |
@kneth unfortunately no! |
@pouyabs5 Not entirely sure what you are doing differently, but I running the unit tests from https://github.com/realm/realm-java/blob/master/examples/unitTestExample/src/test/java/io/realm/examples/unittesting/ExampleRealmTest.java seems to work fine. So I would probably start by comparing those with what you are doing to see if you can spot the difference. Note that we recently merged a small change to |
I am using the example that @cmelchior just pointed out and originally I had |
I assume that removing |
No, it still not working... I tried everything for testing Realm with unit testing and now I'm even thinking about remove Realm from project at all because there is no way that I could test my functionalities or services with unit tests and there already was few more issues. I don't understand how/why other people and you guys from Realm didn't take care about this. I 've lost like 3 weeks searching for solution, and I've lost my patience about this framework and testing. This is not professional solution for ORM for Android. This is my test class with some stupid case: @RunWith(RobolectricTestRunner.class)
} This throws some errors: com.thoughtworks.xstream.converters.ConversionException: Cannot convert type com.sun.org.apache.xerces.internal.dom.DeferredElementImpl to type org.w3c.dom.Node
|
This is an error in Robolectric 's classloading in conjunction with Powermock, see robolectric/robolectric#2208 (although it should have been fixed by 3.3....) |
Ok, If I can't test this with Robolectric, what should I do then? I should test it with what? (Mockito, JUnit...) Is there any complete solution for unit testing? |
@erudonja1 Please keep a civil tone (https://realm.io/conduct/ ). We all know it is frustrating if things do not work, but yelling will not get you anywhere. Did you see our unit testing example which uses Robolectric: https://github.com/realm/realm-java/blob/master/examples/unitTestExample/src/test/java/io/realm/examples/unittesting/ExampleRealmTest.java Note that in recent releases all our public classes are no longer final which means they should be mockable my Mockito. |
@cmelchior i think that works because it uses Personally I could never get Robolectric to work in any slightly more complex setting, with or without Realm. -_- Anyways, if Realm's static accessor methods |
@cmelchior Don't worry, I'm not yelling at anyone, read my comment again, there is no "!!!" anywhere. The accent is in that I don't really understand how I could test my functionalities at all now. This should be your problem No.1 if you plan to use/recommend this ORM somewhere for professional usage. It's not like I have one solution for testing and I didn't make it. The frustration begins when you try 10000 different solutions from your comments and even gists that are incomplete, and neither one is working. And what should I do now? |
@Zhuinden are you saying that this solution worked before for some versions? If it is, could you tell me which and for what version should I use then. please. |
@erudonja1 as I said, Robolectric 3.1 broke PowerMock integration. But Robolectric 3.0 is rather old... the |
@Zhuinden I'm not so optimistic with that version neither but I'll try tomorrow again. |
@Zhuinden Nope... It still not working with 3.0 version. Error message: gradle dependencies: |
@erudonja1 try to create a dummy class |
@beeender but where to put that package and class? If I just create new package with class as it is mentioned it throws this error message: java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/Enhancer
|
@erudonja1 The exception message shows another problem which I have no idea about ... sounds like something wrong between powermock and robolectric. |
@erudonja1 once you fixed issue by creating Powermock only has experimental support of Mockito 2.x (in 1.7.0 RC versions), see https://github.com/powermock/powermock/wiki/Mockito-2-(Maven) The Powermock 2.0 release is scheduled for June 2017. Another option is to revert to Mockito 1.x. |
@Zhuinden @cmelchior @beeender Thank you guys! SOLUTION gradle:
} I also needed to create this class and package, somewhere in project root: package rx; Then you could setUp before test like this: @RunWith(RobolectricGradleTestRunner.class)
} Also I had to override my application class, onCreate method, because in there I was initializing Dagger... public class TestApp extends Application { CONCLUSION: Soooooo, test those methods that are not using database directly...(it's better anything than nothing :() |
@erudonja1 Robolectric claims that they've fixed the classloader issue that broke Powermock in your case in |
Powermock 1.7.0 was released today (2017-06-16) with support for Mockito 2.x See https://github.com/powermock/powermock/releases/tag/powermock-1.7.0 |
When i want to run this simple unit test :
I face this error :
and indicates to the error line in my class that extends from Application where i init the realm :
The text was updated successfully, but these errors were encountered: