0

I have a project that creates both a jni .so file and a java .jar file. All this is working as expected except JUnit test execution. I need the JUnit test to run after the native-maven-plugin creates the .so file. JUnit test will always fail when new JNI methods are added because they are running before the shared library has been created. Is the only option to build twice? Meaning build once skipping test then either execute tests separately or run build again to execute the test?

musterjunk
  • 341
  • 3
  • 15
  • I think you should do integration tests instead via maven-failsafe-plugin.... – khmarbaise May 20 '19 at 19:29
  • What I wanted was integration testing. I am just using junit to drive the JNI integration testing with java. I have a c unit test under the JNI hood. – musterjunk May 30 '19 at 22:40

2 Answers2

0

i guess you are using the native:link goal from the native-maven-plugin?

if you look at the documentation of the goal you see that it is bound by default to the lifecycle phase package.

junit tests (run by maven-surefire-plugin) are run by default in the lifecycle phase test (https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html).

in the maven lifecycle reference you can see that the test phase is before the package phase. this explains why your tests fail after you have made changes. Tests are run first, .so file is generated afterwards.

You can use the maven-failsafe-plugin to run tests after package phase.

add the plugin to your build and name all tests that should be run after package to MySpecificFeatureIT (the suffix IT stands for Integration Test). Tests named MyFeatureTest will still be run in test phase.

see the plugin documentation for more details

abendt
  • 675
  • 5
  • 9
0

Ok, this was a project structure issue. I was trying to get tests that belonged to a different project to run after my JNI .so was built in my JNI project. What I needed to do was put the JNI integration tests I was creating in src/java/test in the JNI project, not another project and try to order them somehow.

jni -  
     |  
     src  
       |  
       java  
           |  
           test  

not

other project-
              |
              src
                 |
                 java
                     |
                     test

of course maven ran the other project test after the other project was built. That is what it suppose to do. Even though the JNI project built a C .so file. The Java rule for testing still apply to the JNI project when it comes to running java tests.

musterjunk
  • 341
  • 3
  • 15