[This article was first published on Romain Francois, Professional R Enthusiast, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is a post in the series Mixing R CMD build and ant. Previous posts have shown how to compile the java code that lives in the src directory of a package and how to document this code using javadoc.

This post tackles the problem of unit testing of the java functionality that is shipped as part of an R package. Java has several unit test platforms, we will use junit here, but similar things could be done with other systems such as testng, …

The helloJavaWorld package now looks like this :

.
|-- DESCRIPTION
|-- NAMESPACE
|-- R
|   |-- helloJavaWorld.R
|-- inst
|   |-- doc
|   |   |-- helloJavaWorld.Rnw
|   |   |-- helloJavaWorld.pdf
|   |   -- helloJavaWorld.tex
|   -- java
|       |-- hellojavaworld-tests.jar
|       -- hellojavaworld.jar
|-- man
|   -- helloJavaWorld.Rd
-- src
|-- Makevars
|-- build.xml
|-- junit
|   -- HelloJavaWorld_Test.java
|-- lib
|   -- junit-4.7.jar
-- src
-- HelloJavaWorld.java

9 directories, 15 files


We have added the src/lib directory that contains the junit library and the HelloJavaWorld_Test.java that contain a simple class with a unit test

And the ant build file has been changed in order to

• build the junit test cases, see the build-testcases target
• run the unit tests, see the test target
• create nice html reports, see the report target