We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Processing + jUnit Tests
Page Index Toggle Pages: 1
Processing + jUnit Tests (Read 2626 times)
Processing + jUnit Tests
Jun 15th, 2010, 7:39am
 
Is it possible to get the jUnit test framework or any other unit tests to work with processing code?

I'm working on a project where I'm required to use processing, but also required to run unit tests on all code written.  Can this be done without creating my own unit testing framework for processing?
Re: Processing + jUnit Tests
Reply #1 - Jun 15th, 2010, 7:54am
 
Yes, it should be possible.
Re: Processing + jUnit Tests
Reply #2 - Jun 15th, 2010, 8:44am
 
PhiLho  wrote on Jun 15th, 2010, 7:54am:
Yes, it should be possible.



Ok, How
Re: Processing + jUnit Tests
Reply #3 - Jun 15th, 2010, 12:26pm
 
It depends...

Are you using Processing from the PDE or via Eclispe or NetBeans (or other)?
In the latter case, you use pure Java, so plugin JUnit in it should be trivial.
In the former case, it is slightly harder, but perhaps you can export the application to HTML, thus getting a jar and even a .java file, so you can test against that.
Re: Processing + jUnit Tests
Reply #4 - Jun 17th, 2010, 10:22am
 
I tried getting it to work today using eclipse (and the proclipse addon since I was having issues getting the serial library's DLL to load properly without it).

This project is more of a proof of concept type of thing.  It's a very simple program that sends a byte to my arduino, and the arduino is programmed to respond with another byte.  The serial communication is done in a "SerialLink" class which as of right now just forwards information to and from the arduino using the Serial library( I didn't use the serial library directly becayse I wanted to learn how to import classes to the PDE environment(if that is what it is called)).  The program works when run as a applet and as an application.

I have a jUnit test project setup which builds against the processing project.  I cannot seem to get the serial port working correctly from the jUnit tests.  I think I'm starting the processing class incorrectly, but I'm not sure how you are supposed to do it.  The only reason I'm starting the processing class is because the serial library's constructor takes a PApplet as a parameter.  I tried creating my own PApplet object and starting the serial connection with that in the test project, but it gave me a null pointer exception (on the serial's constructor).


Currently in the jUnit test project, my setUp method starts the processing class with the following:
PM = new ProcessingMain();
           PM.main(null);  //contains: PApplet.main(new String[] { "--present", "processingtesttake2.ProcessingMain" });
               sl = PM.getArd(); // returns a SerialLink object containing the Serial library's object and a few methods

PM/sl are class variables. This starts up the processing application fine, but it doesn't save a reference to it in the PM variable.

PM.getArd(); returns a null object(because the PApplet.main is creating a different PM object, thus, the serial link objects were created in a different PM).  This is the root of the problem, but i do not know how to fix it with any of the following means:
1) get a valid reference to this processing class that the papplet.main creates so i can retrieve the arduino serial link reference
2) start the processing class without calling the main method so I have a reference to it from the start (calling the setup method of the PM class doesnt work either)
3) start a serial library object with a normal PApplet parent object


Any idea how to get this to work?  If I left out any info, please ask.

Page Index Toggle Pages: 1