Reputation: 31
this is the scenario I´ve got:
I´ve written Java code for an android app which makes use of a c++ library. So the Java code is using JNI in order to be able to use the library. The java code does calls to methods in the JNI layer to invoke the library methods. The thing is these methods are not returning values for the calls I´m making, cause it´s for network stuff, so in the JNI layer I receive some events asynchronously which I send to Java by using callbacks. My question is, how can I junit test this functionality? I mean, how can I test that I do the native methods invocation from Java and I receive in the callback invoked from JNI the expected results? I hope I have explained myself properly, if you do not understand anything do not hesitate to ask.
Upvotes: 1
Views: 809
Reputation: 48272
You could, probably, setup the callback to be a function of your JUnit class, then invoke your API from your JUnit testSmth()
function, then wait on some lock until the callback happens.
In the callback you notify the lock and so your testSmth()
stops waiting and proceeds further and calls, say, success()
.
You can call lock.wait(timeout)
so if the timeout expires you call fail()
from your testSmth()
Upvotes: 1