Saturday, March 28, 2015

Raspberri Pi with Pi4j and Junit testing mockups

Hello, good to see you reading this post !

This maybe not the most efficient way to play with raspberry pi, however JAVA with all its verbosity allows a higher level of abstractions. With unit testing we get much better code maintainability and many other good non functional requirements.

This is a new project to practice how would be a unit tested code of the translated lessons, originally in C code, of the Super Kit for Raspberry Pi Model B. We now have the awesome Pi4J library which exposes nice JAVA APIs of the terrific WiringPi native libraries.

First we need to setup the Pi. You could use the document "Getting started with Raspberry pi.doc" provided with the kit.

If you are curious about how to unit test your JAVA Pi code check my sunfounder-raspi-4j repository with many exercises and testing techniques.

If you just would like to play and run the exercices in your pi, just configure the user and password in the pom.xml file. Update the property "pi.dirCopyTo.dev" to the directory where you want to deploy the jar file. Then run the maven command: 

mvn clean install -Dpi.transfer.dev=true -P FastTests

Then copy the runPi.sh in that directory as well. And it it should be all ready to run the exercise with the command:

sh runPi.sh org.mandfer.sunfunpi4j.Ex0xxx

or

sh runPi.sh  "org.mandfer.sunfunpi4j.Ex0xxx param1 param2"

if you need pass arguments.To finish the sketch just press enter and the exercise  should resume gracefully the GPIOs. I will be updating this project, if you have any question please write a comment.

Many thanks,

Posted by Marc Andreu.

No comments: