Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Developer
Posts: 2
Registered: ‎12-11-2008
My Device: Not Specified

Blackberry Development and JUnit

Hello, I'm currently working on a small project at work where we are developing an application to be run on a Blackberry for a customer. One of the things we want to do is use JUnit to test our code. The problem is that when we make JUnit part of the project, it won't build anymore. Is there any way to be able to run our unit tests and still be able to build the application as we normally would? Some additional information: JDK 1.6 Update 10 Eclipse Ganymede (3.4.1) Blackberry Eclipse Components version 4.6 JUnit 4.5 If there's an alternative, I'd like to know. I also tried Bunit, however that had the same problem. I'm liking JUnit much better anyway since I can tie it into Eclipse and not have to run the simulator. Thanks in advance.
Posts: 17,005
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Blackberry Development and JUnit

you won't be able to test blackberry code with JUnit (because annotations are not supported in java 1.4/j2me, among other things). there are some other tools available, take a look here: http://www.developer.com/ws/other/article.php/10949_3760891_1

personally i am using JUnit to test my webservice implementations, it is a bit difficult because eclipse has both the jde and j2se libraries (and i keep using add instead of addElement for vector, for example) but it works quite well.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 2
Registered: ‎12-11-2008
My Device: Not Specified

Re: Blackberry Development and JUnit

Thank you for your reply. Unfortunately, a very similar problem exists with that tool: if I compile to run, my application isn't run, the unit tests are. What I was hoping for is some way to exclude my unit test code/libraries when I want to run the application. When I tried BBTest and tried to run the application, I could only run the unit tests and not the application itself. Now, as for testing using JUnit, so far it's working fine. I don't use annotations. I just extend the TestCase class to create test classes and use the asserts.
Posts: 292
Registered: ‎07-25-2008
My Device: Passport

Re: Blackberry Development and JUnit

Trying to use normal JUnit for BlackBerry development is a waste of time, unfortunately.  The BlackBerry API is not the same as the J2SE API, nor can it be used outside of the simulator.  The only way to really do unit testing is on the simulator.  To do that, you need to use a J2ME-friendly (and BB-friendly) unit testing framework.


The most serious ones I've seen so far are J2MEUnit and CLDCUnit, and while the latter looks like a better solution, I've thus far only had experience with the former.  I recommend Googling for them, and seeing what you can find.


For one set of examples, feel free to look at some code I put into my own project for testing...


The full source to J2MEUnit, plus a BB-specific quick 'n dirty (but nice looking) test runner UI that I wrote:



Some of the actual test code for my project, as a usage example:



I have been thinking of taking this (and/or something CLDCUnit-based) and spinning it off as a separate project.  Such a framework is sorely needed in the BB development world, and would benefit greatly from being an active BB-focused project.