Surefire JUnit Testing Using Native Libraries

We use Maven in Hudson to start the Java build process and the Surefire plugin to run JUnit tests, however, I had a problem with unit tests for a single project that requires its own DLLs.

The error we see is:

Error Tests: TestFormRegistrationServiceConnection (com. # Productidentifierremoved # .test.RegistrationServiceTest): no Authenticator in java.library.path

Where Authenticator is the name of the required DLL. I found this SO post , which suggest that the only way to set this is via argLine. We changed our configuration as follows:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.10</version> <configuration> <forkMode>once</forkMode> <argLine>-Djava.library.path=${basedir}\src\main\native\Authenticator\Release</argLine> </configuration> </plugin> 

However, this still gives the same error and includes System.out.println (System.getProperty ("java.library.path")); we can see that this is not added to the path.

Any ideas how we can solve this?

+7
source share
1 answer

To add a system property to JUnit tests, configure Maven Surefire Plugin as follows:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <java.library.path>${project.basedir}/src/main/native/Authenticator/Release</java.library.path> </systemPropertyVariables> </configuration> </plugin> </plugins> </build> 

Update:

Well, it looks like this property should be set before starting the JVM with JUnit checks. Therefore, I assume that you have backslash problems. Backslashes in the value of a Java property are used to call special characters, such as \t (tab) or \r\n (newline windows). So try using this instead of your solution:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <forkMode>once</forkMode> <argLine>-Djava.library.path=${project.basedir}/src/main/native/Authenticator/Release</argLine> </configuration> </plugin> </plugins> </build> 
+5
source

All Articles