8

I have an Android JNI wrapper for some C++ code. The C++ code has it's own set of unit tests.
I want to write Java unit-tests for the JNI wrapper class.

Is there a way to unit-test the Android JNI .so wrapper API from the desktop console e.g. on Windows? Maybe using a desktop Java framework but with all the Android SDK calls?

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137

1 Answers1

1

Since the class that calls into native is just a wrapper class, then you can just unit test the JNI layer. If that is what you want, then it would be a bit hard to unit test your JNI functions directly. However, you can still take the "core" of your JNI function that does all the work and put that in a separate .c file. So basically, you would include your new class in the JNI class and make that class do all the wor. Now, you would have a .c class with a set of methods that can be easily unit tested.

Hope that helps!

sasfour
  • 399
  • 1
  • 3
  • 10
  • 1
    Yes, this can be a good method and is very efficient, but it's important to be aware that different platforms and C libraries behave in subtly different ways - for example subtle errors can be experienced different on a 32-bit Android system than when built for a (typically) 64-bit development host - it won't necessarily catch risky assumptions about implementation-defined behavior. – Chris Stratton Aug 14 '14 at 22:08
  • As I said in the question the C++ code already has it's own unit-tests, as does a C wrapper for the C++ API. What I want to UT is the JNI code, which often has platform specific data conversions which cannot really be ported or isolated to native C. – Adi Shavit Aug 15 '14 at 19:19