Thursday, November 10, 2011

RMI Registry port may be used error

I have got a new (a bit more powerful) workstation and was installing everything there. I started downloading all new versions of the tools that I have been using, like new Eclipse, JDK 1.7 etc.

Then when I ran Nokia S40 5th edition emulator, I go this error:

The internal RMI registry port 1099 may be in use by another application.




I tried to change the port, killed all other java apps, but no luck.

In the end, the problem turned out to be a jdk/jre bug. Apparently, the bug surfaced since 1.6 u 29. Here is the bug report. in sdk release note.

So switching to older JDK should fix the problem. I uninstalled jdk and installed JDK1.6 update 23 and it's working fine now!

Friday, November 4, 2011

Android code coverage

Unit tests are definitely a programmer's good friend (when done properly), watching the back and confirming that everything is working alright.

Code coverage is a friend of the unit tests, telling unit tests how well he has covered up his friend.

Anyways, I will give a quick and short instruction here about android unit testing.

Guess what? This is really simple if you have ever written any unit tests before for Java apps. It's all the same

  • First step, create a separate project for unit testing. When you create this project in Eclipse, eclipse will ask you to point to the existing project that you are going to test.
  • Write some unit tests. You will create test cases by extending AndroidTestCase class
  • Run the test, and see if the test method is actually being executed or not. Tests will be run in the emulator / device like a normal app, and will notify to eclipse. Use Eclipse > Show View > JUnit to see the result. There are notes about it in the same link I mentioned above.
  • Now getting the coverage report could not be any simpler:
    • create the ant script for building the test project. Open command prompt and go to your test project directory:
      • android update test-project -m <your_main_project_full_path> -p .
    • and run
      • ant coverage
Done!!!
Look for the coverage directory under test project and a nice report it waiting there.

Now if you are running in windows you may get this error
 "<something like File or SDK > was unexpected at this time.", 
then ant could not find some path. I hate windows "Programs Files" directory, cause that contains a space and space is an enemy for ant. So try Installing your sdk in a path that does not contain any space, and that should resolve it.