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

Add example of running junit tests calling native code #9

Open
sureshjoshi opened this Issue Nov 14, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@sureshjoshi
Owner

sureshjoshi commented Nov 14, 2017

A problem with running native code is that you often need to use the instrumentation tests to run unit tests.

Actually, in reality, you just need to compile your libraries for your platform (as junit runs on your computer's native platform).

@sureshjoshi sureshjoshi self-assigned this Nov 14, 2017

@sureshjoshi

This comment has been minimized.

Owner

sureshjoshi commented Nov 14, 2017

Rough CMake is

if (APPLE)
  find_package(JNI REQUIRED)

  find_package(SWIG REQUIRED)
  include(${SWIG_USE_FILE})

  include_directories(${JAVA_INCLUDE_PATH})
  set_property(SOURCE SeePlusPlus.i PROPERTY CPLUSPLUS ON)
  swig_add_library(SeePlusPlus_Wrapper LANGUAGE java SOURCES SeePlusPlus.i)
  swig_link_libraries(SeePlusPlus_Wrapper SeePlusPlus)
  add_library(protobuf-lite SHARED IMPORTED)
  set_target_properties(protobuf-lite PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/osx/libprotobuf-lite.dylib)
  target_link_libraries( # Specifies the target library.
                         SeePlusPlus
                         protobuf-lite)

And then

    @Test
    fun addition_isCorrect() {
        val wrapperLib = File("app/src/main/jniLibs/osx/libSeePlusPlus_Wrapper.jnilib")
        System.load(wrapperLib.absolutePath)
        var mCpp = SeePlusPlus()
        val result = mCpp.Multiply(5, 1)
        Assert.assertEquals(5, result)
    }

sureshjoshi added a commit that referenced this issue Nov 16, 2017

See #9 - Proposing a rough solution for native JUnit tests not running.
Essentially, JUnit runs on the computer's platform, so having Android NDK-built libraries is of no use. Need to re-build these libraries 'natively' - using Mac/Linux/Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment