Saturday, September 18, 2010

Fewer Posts

Since I am starting my MBA from this September, this blog will see fewer posts. Nevertheless, I will log my technical learnings in general as I come across them! So, don't think I am gone, just hibernating :).

Wednesday, May 19, 2010

Debugging Tests For Blackberry Development in IntelliJ Idea

Thanks to Andrew's persistent and genius effort, the team now has a way to debug the tests in IntelliJ Idea for BlackBerry development. This still does not debug UI code in simulator, but is still a huge jump forward to help the team with super-effective unit testing. The build file has been updated to reflect the changes. Besides using this build file and the structure mentioned in the previous post, you need to follow these steps:

1. Lets assume your main application project is called SampleApp. This should appear in your Idea project as a single module. Create another module for your project and name it "testing" (say)

2. This will create a "testing" folder on your hard disk. Create an empty folder under the module and name it "src". In the project module settings set this to be source folder for the module

3. Using the ant build file, first build and test your SampleApp. This will create a "tests.jar" in the "test_build" folder and a "SampleApp.jar" in the application folder

4. Now, for the testing module open the module settings and go to the "Dependencies" pane. Add the SampleApp as Module Dependency. After this add the SampleApp.jar and test.jar. Finally, add all the dependency jars that we added for SampleApp and all the jars in the lib folder of the installed Ant. Use J2ME SDK as the module JDK

5. Now, open Run->Edit Configurations. Add a new configuration to "Application" and name it "ant run". Set the following parameters:

Main class: org.apache.tools.ant.launch.Launcher

Program parameters: -buildfile bb_build.xml -Dbasedir=C:\development\code\SampleApp test
(the base directory of your project with the ant build file in it)

Working Directory : C:\development\code\SampleApp
(has your build file)

Environment Variables: -Dant.home=C:\development\ant_installation

Use classpath and JDK of module: testing


Voila! You are ready to debug your tests! Put a break-point in your tests in SampleApp module and debug the testing module using this configuration.

Monday, May 17, 2010

Ant Script for Blackberry Development in IntelliJ Idea

To say that developing Blackberry J2ME applications is a nightmare is an understatement, especially is you wish to setup a comprehensive build and test environment for the team. It is possible to do things in bits and pieces, but having a single integrated development environment handle it all gracefully looks like a distant dream, forcing us to move to Ant and use its build scripts to get a build environment that is not only independent of the IDE but can also be used in continuous builds. Many thanks to Andrew for helping us to get this far. I have compiled the steps needed to set up the Ant environment in IntelliJ Idea.

1. Install Sun's Java ME SDK

2. Install Ant such as its path does NOT have a blank space in its installation path name

3. Install the relevant version of RIM JDE and emulator

4. Create an ordinary Java project. Change SDK to ME in project settings (Project Settings->General, you can bring up the dialog from File->Settings)

5. Check the folder in which the project has been created. Create the following sub-folders inside it: application, bin, lib, src, test, test_build, test_results. Within "test_build" create a "classes" folder

6. Even though you could link jar files from anywhere in the system, it may be a good idea to put following jars for following projects at one place in the lib directory:

Blackberry Ant Tools
JMUnit and Hammock
JDOM
J2MEUnit
Microemulator

Additionally, to make your life easier while coding, copy the net_rim_api.jar from the lib folder of the installed RIM JDE

7. In project setting (Project Settings->Modules), set "src" as the source folder and "test" as the test folder. In dependencies, add jars for RIM, JMunit, Hammock and J2MEUnit.

8. Expand the "Ant Build" panel and open properties dialog. Under execution, use custom ant and point to the intallation that does not have any blank spaces in its path. Under Additional Classpath, add all the jars that we had put in step 6. Be sure to have the ant tasks for JMUnit and Blackberry Ant Tools.

9. You are all ready to start coding under your "src" folder and write tests under your "test" folder. Now we need a build file that can enable you to actually build and test your code. For that, make a "build.xml" file, which will be your ant script, and place under the root folder. Use this script provided for you. Don't forget to adjust the paths as per your installations. With some luck, this should bring up 8 tasks on your pane: build, build_and_deploy, build_deploy_and_launch_simulator, launch_simulator, test, test_compile. Note that the build task will not launch test task in the current script, but you could change it if you please.

These tasks will accrue you the following benefits:

1. You can write your blackberry development code in Idea
2. You have an ant script that can be used to make contunuous builds and tests. The test also generates reports that are stored under the test_results folder.

My team has still not found a satisfactory answer to debugging, but current set-up helps us to develop using a more effective tool and get our automated build systems to run effectively for the wretched J2ME. Moreover, this Ant script can be run from any IDE (with similar configuration for the ant used). It is still not 100% perfect, but we are getting there: constantly thinking about testability, logging and sustainability of build environment. I will keep updating the build file so as it gets more comprehensive.

PS: We were able to build and test using Ant and Netbeans, but the build/deploy part was tightly coupled with Netbeans, which was not encouraging for automated build tasks.

Wednesday, April 14, 2010

An Ode To Testing

Even though I am all for quality, testing can get torturous at times. So here is a fun take on the perils of testing by yours truly :)

"O Horrible testing, in ways so many of thee
You take pleasure in tormenting me

Test cases are many, JUnit is one
And these useless stubs under the sun
Trying to focus my eyes water
As my head starts feeling hotter
And I yawn and I fall
Horribly sleepy one and all
In search of quality I seek thee
But a JMocking venomous smirk is all I see
Murderously as you try to JRun me
Yes, you take pleasure in tormenting me"

Tuesday, April 13, 2010

Thinking Quality: Basic Thumb Rules

Quality of code is often a critical issue in a development team. Ensuring the quality can get complicated for a variety of reasons, so let us explore the possible ways to ensure code quality.

First, it is important to get the programmer to think how he can keep improving the quality of his code. Bugs are inevitable, but that is no excuse for shabby programming. However, it is difficult to get most developers to take this seriously without antagonizing them. Nevertheless, making unit testing integral to development can check many if not all bugs. People can also be encouraged to develop a customized check-list for themselves to help them avoid common mistakes. Having a "company-wide" check-list may prove to be both counter-productive and bureaucratic.

Second, code reviews can be useful. However, it can cause antagonism within the team and people may be reluctant to criticize each other. Moreover, it can be done effectively only by senior and more experienced people in the team. Anonymous, time-bound reviews is one potential answer to use this tool.

Third, using Agile and related development technologies will help the manager to leverage the full experience of the team, get them closer to the requirements and avoid many bugs related with misunderstanding specifications.

Finally, the productivity of the team is the function of morale. Morale for different people can mean different things. The best way, however, to build it is by having a clear vision for the company and being able to percolate it meaningfully in every aspect of work. Further, focus on the strengths and interests of each team member instead of focussing on their weaknesses.

Thursday, February 4, 2010

Nested Table Component for Blackberry

Based on our last Simple Table component, I have put together a Nested Table as well. The main features are:

-Each row can be rendered like an irregular table
-Each row is backed by an object
-Possibility to add a popup to row click

These classes demonstrate how to use the component:
SampleApplication.java
SampleRowBackingBean.java
SampleBean.java

You would need the following classes to make this work:
BNestedTable.java
BMultiRowBackingBean.java
BGenericTableCallback.java
BAbstractRowRenderer
BNestedRowRenderer.java
BSimplePopupScreen.java
FieldCreatorUtility.java
UiProperties.java

Possible improvements:
-implementing varying row heights
-implement table header, table footer and column header

Wednesday, February 3, 2010

A Simple Table Component for Blackberry

Just worked on making a J2ME based prototype for a Blackberry (JDE 4.7+). The documentation, the website and the API are horrible, to say the least. We are using the Eclipse Plugin for development. One of the prime difficulties we faced was the absence of a well-defined table component. "ListField" is horribly designed and the example that is given in their documentation does needs serious improvement. Moreover, to make a flexible component that renders a list of messages (like the SMS message list) with each composite row selectable as a whole, no example could really help. So, I have made two components that you can improve upon and use as you please.

The first one, that is given in this post, is a simple table. It takes a 2-D array of fields and converts it into a visual table. It simply improves upon ListField. You would need the following three classes:

BSimpleTable.java
BSimpleTableCallback.java
BSimpleRowRenderer.java

Then in you code, use a similar code snippet to make and add a table (here we use it to create the title of the screen):

Field[][] titleContent = new Field[1][];
titleContent[0] = new Field[3];
titleContent[0][0] = new LabelField("S.No.",
DrawStyle.ELLIPSIS);
titleContent[0][1] = new LabelField("Message",
DrawStyle.ELLIPSIS);
titleContent[0][2] = new LabelField("Time",
DrawStyle.ELLIPSIS);
int[] widthPercent = {10,63,27};
int[] paddings = { 5, 0, 0 };
setTitle(new BSimpleTable(titleContent,
widthPercent, paddings,
Field.NON_FOCUSABLE));

If you don't want to sign the application, hard code the total screen width instead of using Display.getWidth()

Also, see: Version Specific Developmnet Guides (3.6 to 5.0 beta)