Automatic running of unit tests

212 views
Skip to first unread message

Mark Doyle

unread,
Jan 29, 2014, 9:54:19 AM1/29/14
to mave...@googlegroups.com
Hi all,

Is it possible to have native unit tests run as part of the build, just like a Java Project?

The Nar Maven page seems to imply this:

nar-testCompile

This goal will compile the native test source code (c, c++ or fortran) and create executables from it. 


I have no idea how to go about this though. I'm attempting to use NAR to build a shared library (which is working) but I'd like to unit test the classes. I have no preference for a particular unit test framework if that helps any.


Thanks!

Greg Domjan

unread,
Jan 29, 2014, 11:27:25 AM1/29/14
to mave...@googlegroups.com

There is nothing provided by NAR specific to native only to enable this right now. 
It seems to me that the nar test goal aims to extend the java unit test for JNI testing.

Native test executables that are built can be marked to run.  So just a few options on how it could be done with
 * writing your own 'unit test' app
 * package a native unit test sdk like cpp unit - my earlier note on this https://groups.google.com/d/msg/maven-nar/r7j7RpWe32Q/U4zBRc5Ps6IJ  - and have a unit test runner
 * write java based unit tests and some jni to call to the native - this seems a bit obfuscated to me

It would certainly be nice if such a thing could integrate with surefire and be managed just like other parts of the build.


Greg

Johannes Schindelin

unread,
Jan 29, 2014, 11:30:56 AM1/29/14
to Mark Doyle, mave...@googlegroups.com
Hi Mark,

On Wed, 29 Jan 2014, Mark Doyle wrote:

> Is it possible to have native unit tests run as part of the build, just
> like a Java Project?
>
> The Nar Maven page seems to imply this:
>
> nar-testCompile

Note: before reading your mail, I had no knowledge of the internals of the
testCompile goal. For your benefit, this is how I improved my knowledge:

- I cloned https://github.com/maven-nar/nar-maven-plugin

- Inside the working directory, I called

git grep testCompile

and identified the most likely candidate to enlighten me to be the file
src/main/java/com/github/maven_nar/NarTestCompileMojo.java

- Then I inspected that class' execute() method.

After these steps, it looks to me as if testCompile only compiles the
native test sources in src/test/c/ (or src/test/cpp/ or ...).

However, it does not run them. A look at
src/main/resources/META-INF/plexus/components.xml corroborates that, but
suggests that "nar-test" is actually what you are looking for. A quick

git grep 'nar-test$'

leads the hunt to src/main/java/com/github/maven_nar/NarTestMojo.java in
whose narExecute() method calls runTest() and runExecutable(), hinting at
the correct way to do it: Add a <tests> section to your configuration.
An example can be found in the source code repository, too:

https://github.com/maven-nar/nar-maven-plugin/blob/f8f656b0/src/it/it0007-lib-shared/pom.xml#L59

Ciao,
Johannes

Mark Doyle

unread,
Jan 29, 2014, 11:44:20 AM1/29/14
to mave...@googlegroups.com

Looks like you can after all. The configuration page (http://duns.github.io/maven-nar-plugin/configuration.html) has a section on tests. Unfortunately, I couldn't respond to my own mail until it was accepted :)

Pretty simple in the end.

Next job, converting a testing framework to a maven nar to use as a test dependency.
Reply all
Reply to author
Forward
0 new messages