How can I easily unit test Blackberry code?
blackberry, java, tdd, unit-testing
Solution
Mockup testing
Youre on the right way about mockuping, but I wouldn't advice you to test Blackberry functionality on J2SE platform. I think proxys and mockups should be used in case when there are no testing data available in native source, examples:
"scan for other devices" - there are no other devices but you wan to test scan functionality "TCP over the Wifi interface" - you want to test it on Storm (no WiFi) "logging our GPS location" - device location is static, but you want to test other locations
Then you can mockup such functionality using Blackberry platform: BlackBerry GPS location mockup
Still you can reproduce BlackBerry API class on J2SE from the scratch simply using same names and signatures. That would presume youll have to implement all class functionality by yourself.
Testing j2me without simulator
That would be a really great option, but so far I can't see how to do this.
Testing involves application running and this involves platform simulation. There can be some possibility to test j2me code without whole UI simulator running but I don't know it.
What you can do is test some business logic on Java Standard Edition with minimum code changes.
You still need to run platform dependant functionality testing on simulator, but you can do it in one application, which would be a set of unit tests, like ChrisW already said. Simply run test methods one by one and output results on screen: Method1 - Passed - 0.03 s Method2 - Passed - 1.30 s Method3 - Passed - 0.25 s
J2MEUnit
http://j2meunit.sourceforge.net/:
J2MEUnit is a Java 2 Micro Edition (J2ME) library containing a unit testing framework for J2ME applications. It is based on the source code of the original JUnit, the successful unit testing framework for the standard (desktop) edition of Java, J2SE.
Unit Testing J2ME applications with J2MEUnit and Eclipse Quick Tutorial to setup & learn J2MEUnit
JMUnit
http://jmunit.sourceforge.net/:
JMUnit is a unit test framework for Java ME (J2ME) based on JUnit. It has the following features: - Works in both the Sun emulator and on actual devices. - Is small (tests can be run even on old MIDP 1.0 devices). - Has a comprehensive collection of Assert methods for checking test failures. - Both TestCases and TestSuites are supported. - Includes Ant tasks for running JMUnit tests in a continuous build. - Has performance monitoring classes inspired by JUnitPerf.
Writing and running JMUnit tests
BUnit
Unit Testing library for RIM Blackberry based on jmunit
http://sourceforge.net/projects/b-unittesting/ BlackBerry Support Community Forums: How to do unit testing my Blackberry Application
Additional
How To - Automate testing with the BlackBerry Simulator
Problem
For my university class we are developing a multi-threaded Blackberry application which allows us to scan for other devices running our application with Bluetooth and then transfer files to each-other by TCP over the Wifi interface, implementing NAT traversal, all the while logging our GPS location. (It's a RIM sponsored Computer Networks class in case that wasn't obvious yet.) I have grown fond of Test Driven Development and was going to employ it for developing my homework assignment. However, any Blackberry class which I extend or otherwise call during testing gives me a ClassFormatError due to illegal modifiers. I presume this error is caused because the jar with the Blackberry code must have been specially compiled for their proprietary JVM. So far I've resorted to using the Proxy Pattern and implementing Mock Objects of the proxies. However, this is getting very tedious since I'm inheriting from many native Blackberry classes. I would also like to avoid having to launch the Blackberry simulator if possible. It can take minutes just to boot it up and this is impractical and annoying for unit tests. Is there am easy way to unit test my Blackberry code?