android - UnsatisfiedLinkError when unit testing WritableNativeMap -
i creating android library use in react native project. need emit map javascript, i'm using react native's writeablemap class. unfortunately, class loads reactnativejni in static block, leads unsatisfiedlinkerror during unit tests. i'm using junit , mockito test.
my code:
@override public void onsomething() { writablemap params = arguments.createmap(); //fill map sendevent("onchange", params); } the error:
java.lang.unsatisfiedlinkerror: no reactnativejni in java.library.path @ java.lang.classloader.loadlibrary(classloader.java:1857) @ java.lang.runtime.loadlibrary0(runtime.java:870) @ java.lang.system.loadlibrary(system.java:1119) @ com.facebook.soloader.soloader.loadlibrary(soloader.java:172) @ com.facebook.react.bridge.nativemap.<clinit>(nativemap.java:23) @ com.facebook.react.bridge.arguments.createmap(arguments.java:29) @ me.myclass.onsomething(myclass.java:23) i started using arguments.createmap() method after seeing comment stubbing writeablemap unit tests, it's static , prefer not have stub static method.
is there way rid of error when running unit tests?
i don't think can avoid mocking arguments methods in unit test (though believe not need in instrumentation test).
in facebook's own tests, use powermockito mock them: https://github.com/facebook/react-native/blob/master/reactandroid/src/test/java/com/facebook/react/rootviewtest.java#l67
interesting bits:
powermockito.mockstatic(arguments.class); powermockito.when(arguments.createarray()).thenanswer(new answer<object>() { @override public object answer(invocationonmock invocation) throws throwable { return new javaonlyarray(); } }); powermockito.when(arguments.createmap()).thenanswer(new answer<object>() { @override public object answer(invocationonmock invocation) throws throwable { return new javaonlymap(); } }); also note requires modify build.gradle include these mocking tools: https://github.com/facebook/react-native/blob/master/reactandroid/build.gradle#l266
dependencies { ... testcompile "org.powermock:powermock-api-mockito:${powermock_version}" testcompile "org.powermock:powermock-module-junit4-rule:${powermock_version}" testcompile "org.powermock:powermock-classloading-xstream:${powermock_version}" testcompile "org.mockito:mockito-core:${mockito_core_version}" testcompile "org.easytesting:fest-assert-core:${fest_assert_core_version}" testcompile "org.robolectric:robolectric:${robolectric_version}" ... } the versions use can found in gradle.properties file.
i don't know how stable these test configurations on long run, configuration has let me work readablemap/array , writablemap/array in unit tests.
Comments
Post a Comment