Saturday, October 31, 2009

First, I describe what is TDD. Then, I present a story that lead me to writing this article. But if you don't care about stories, just skip to Conclusion and Resources

What is TDD?
I'll describe TDD not with my own words but with a few selected excerpts from this resource:

The practice of maintaining automated unit test suites has gained widespread acceptance over the past decade to the point where most developers today either engage in some amount of test writing or at least feel bad for not doing it.

To prevent regression, developers must provide a set of tests that exercise an application top-to-bottom and end-to-end (front-end to back-end), but anecdotal evidence suggests that even automated tests covering as little as 50% of the code can effectively guard against regression in many applications.

Competent developers either conform to a test-first discipline in which small test harnesses are built to exercise an API before the API itself is even implemented, or else employ a code-a-little-test-a-little (CALTAL) approach in which each unit of code developed is tested immediately after its compiled.

Most build systems, such as ant, provide direct support for running test suites as part of the application build process, and continuous integration systems, such as Cruise Control or Hudson, kick off such builds automatically each time code is committed to the team's version control system

Situation
Recently, I ran into project OpenSatNav. It's an open-source version of AndNav2, that is navigator application for Android OS based on OpenStreetMap. Great project, still pretty young, but dynamically expanding. I watched a few issues being fixed by the developers involved, and noticed that the process of findind a solution was a bit erratic. There were several attempts to guess a solution, and guesses were not perfect, but then there were a few better guesses. Some NullPointException bugs cropped out after a few days and were fixed. Still, some issues were reported, but never reproduced, so by the token "it doesn't show the problem anymore, so let's close this issue", the issue has been closed. What was obvious to me, is that the solution is not necessarily correct. The testing was done manually and without even any systematic approach.

Spring into Action
It was obvious to me that what was definitely missing, was the automated testing, especially unit testing. I tried to step in and encourage unit testing. The idea of TDD, or any unit testing that I proposed several times was for the project team like a fairy tale about a bad wolf. But the developer team and the project lead were friendly and not exclusive.The lead-developer on this issue, responding to my requests, did include a well defined test-scenario with the fix code. I thought: it's not bad, I'll step in and write a unit or functional test for this fix. I have experience with TDD for Android, Java, GWT and Flex projects.

Result
It took me time (I have a full-time job and four children ages 4 - 19, plus, I took this as an opportunity to review the currently best practices for testing for Android OS), but finally I got to writing the test. And here's what I have found, which may be very well what also you experience is in this matter. While writing a unit or a functional test for your own fix or new feature is a fun and a relatively straightforward activity, writing a test for a code written by someone else, is neither much fun nor simple. You end up reverse engineering the whole part of the system that surrounds the part where the fix was made.

Conclusion
Simple. Write your own tests. This, was for me always fun and an enlightening experience. And, I think, my design and coding have improved because of the tests I wrote. Tests for my own fixes. Tests written immediately after I have written the code (CALTAL), or even just before I have written the code.

Resources
The following are useful for getting quickly to speed with TDD, esp. for Android OS development:

Thursday, October 29, 2009

After it's created, you may find an error in web.xml: Cannot find the declaration of element 'web-app'. To fix it, change all occurrences of j2ee to javaee in the attributes of the web-app tag in web.xml.

Place all jars required by your app:

into yourWebApp/WEB-INF/lib folder if you want just your app to acces it

into tomcatHome/shared/lib folder if you want all web apps on the server to share it

into tomcatHome/common/lib folder if you want all application and the server to be able to use it

To start the server: go to bin folder and fire-off the startNetworkServer.bat or the like on other OS's.

To create a database: connect to the server with the following JDBC URL: jdbc:derby://localhost:1527/fiber1;create=true. Replace fiber1 with the name of the DB you want to be created upon connect.

There is a tool called DdlUtils freely available from Apache that allows migration from one DB vendor to another. That means migration of the schema and the data. Can be used via Ant or from a Java program.

Saturday, October 24, 2009

Recently, oe of our laptops failed. It was slowly getting worse and worse. We had to recover the files, but the installed windows OS wasn't operational any more. I have run into a SystemRescueCD. It's an open project, that provides a set of rescue-oriented tools, togather with the basic linux system on a bootable CD or USB.

Mount the USB to copy the files onto:mkdir /mnt/sjb/usbmount -t vfat /dev/sdb1 /mnt/sjb/usb (vfat is an extension of fat16)

I have also used an external harddisk connected via USB to copy a larger amount of data from the laptop's harddisk. To find which device name I should point to to mount it (like /dev/sda1), I have used the testdisk utility available on the CD.

Friday, October 23, 2009

We have experienced problems, on some of our computers, when trying to use Office Connector plugin with IE. Office Connector is a plugin that allows to easily edit an attached office document in its native editor, whether MS Word, Excell or OpenOffice Writer or some other. In Firefox, it works very well, once you install the add-on. But in IE, it displays a message:

Unable to create an ActiveX object to open
the document. This is most likely because
of the security settings for your browser.

Notes:

The SharePoint.OpenDocuments ActiveX class is installed as part of MS Office, as part of Office Tools. The problem is not related to the IE version (both, IE6 and IE7 sometimes worked and on other computers didn't).

If you try to open for edit a document attached to a confluence page, the above class gets loaded into IE, and can be found in the list of loaded IE extensions.

To verify that it's installed correctly on your machine, run the scriptWScript.Echo "About to create an new SharePoint.OpenDocuments.1"dim objset obj = CreateObject("SharePoint.OpenDocuments.1")WScript.Echo "Finished"

After tweaking the existing versions of the MS Office on the machine, it started working.

Friday, October 2, 2009

On that website, provide the complete name of the package, but only the name, in main search box.

Run: rpm -Uvh name_of_the_rpm.rpm

The nice thing: this command will not install anything until all dependencies are satisfied.

If any dependencies are unsatisfied, this command will indicate what is needed. Download it and append the name of additional .rpm file(s) to the command and execute again. Continue the loop until all dependencies are satisfied.