Showing posts with label J2ME. Show all posts
Showing posts with label J2ME. Show all posts

2010-01-12

J2ME Unit Testing

In the past I tried to get happy with unit testing of J2ME code.

I used JMUnit and J2MEUnit. JMUnit is a lot more straight forward while J2MEUnit is a high ceremony framework which requires a lot of boiler plate code just to be as much like JUnit as possible.

But in the end both suck. All J2ME testing frameworks will suck.

Why? Because unit testing should be easy and fun but compile, preverify, deploy to the emulator or the device, doing some manual steps just to see that something is broken isn't fun and it's also not easy.

There is a lot of stuff you have to try on the phone but that has nothing to do with unit testing but it's tinkering around implementation issues. You will have to do that anyway and I guess both frameworks are of little help here.

So what is the answer to J2ME unit testing?

In my opinion the best approach is to do unit testing on the PC inside the IDE. Using JUnit 4 and Java SE.

I'm currently giving this solution a try. I have a separate project with a dependency on the J2ME project.

For all those J2ME classes you need stubs. I haven't found usable code on the net so I write them myself. (I don't have a lot of them yet)

The good thing is you can really take control over everything with your own implementation of the J2ME classes. Your own bluetooth connection, file connection ... you name it. It's a lot of work but you can do almost anything. Once you have your mocks and stubs in place you will see how much better this approach is.

But the best about this is that the tests run fast, you can exhaust all the cool stuff from your IDE from good debugging support to integrated JUnit support, you can use mocking frameworks like Mockito, EasyMock etc., you can use a modern framework  (JUnit 4)  and you could even use coverage analysis integrated into your IDE (but I haven't tried it yet).

It should also be easy to integrate this into the build and run the tests on the CI server. (This is a nightmare with the "pure" J2ME solution.)


This idea is inspired by an experimental approach to unit testing on Android which is something I will try on one of my next Android projects.

2009-12-24

Fragmentation is inevitable

Many J2ME developers are complaining about device fragmentation. And I agree that it's one of the hardest challenges when developing portable MIDlets.

Recently similar things are said about Android. (see http://androidandme.com/2009/11/news/what-does-android-fragmentation-look-like/ )

And even on the iPhone there are similar problems. And I think that those problems are inevitable when you don't want to stick to old and outdated technology.

But why does fragmentation occur? What are the reasons for it?

  • Different software / hardware vendors. Even if the specs are very similar the details of an implementation can make the difference. This affects J2ME a lot. Luckily Android devices are more similar in terms of OS implementation but the hardware varies. The iPhone is the clear winner here. There's only one vendor. (Well this is in my opintion one of the few things that are good about having one vendor only.)
  • Software evolution.  (i.e. new versions) Software normally gets better and better with each revision and usually users want to use the latest features. But not all users can or want to update their devices. So you have to deal with multiple versions.
  • Hardware evolution. New devices have higher screen resolutions, more memory, more sensors etc.  If you want to make use of those new capabilities and don't want to break compatability with less powerful devices you have to write smart applications.

In the end device fragmentation is the consequence of device evolution. And we have to live with it because it won't go away.

Even controlled platforms like the iPhone are affected by this. Not as much as others but even iPhone developers have to deal with it. The next big change to that platform might be the introduction of new HD models with higher screen resolutions. We will see how those developers can deal with it. On other platforms people are already used to different screen sizes but I guess only few iPhone developers today think about screen size.

2009-11-19

My guess on the fate of Symbian

According to the blog "The Really Mobile Project" Nokia is going to replace Symbian with Maemo on the high-end smartphones.

While Maemo looks quite cool I think this isn't the end of Symbian. Instead it might become the end for S40 since my guess is that Nokia will start to use Symbian for mid-range and - in the long term - for low-end phones. (Although I don't expect it to power ultra-low-cost phones like the 2330 anytime soon.)  Both market segments are not suitable for a heavy-weight like Maemo.

This makes a lot of sense since Nokia invested a lot of money into the platform and Symbian might be much more future-prove than the proprietary S40 platform.

Beside that Symbian (S60) is still one of the best platforms to run J2ME on.

Maemo: It will have to compete with Android and iPhone. I don't know if it will really gain momentum.

But only time will tell.

2009-10-20

ProGuard 4.4 has some problems (with MIDlets)

Recently I found out that obfuscating one of my MIDlets with ProGuard 4.4 resulted in a broken application. The application did start and most of it worked but some of the features were broken.

The good thing is: After going back to 4.2 everything was fine again.

Unfortunately I hadn't had the time to investigate more on this but if you run into similar problems when using a more recent version of ProGuard you are warned by now.