My name is Juri Strumpflohner and this is my technical blog. I'm a software architect, .Net, Android, Web and Java dev, TDD and best practices promoter and martial arts practitioner.

Recent Posts Subscribe

Dear reader of Juri's TechBlog,
I moved my blog to a new domain and a new hosting solution as well. I'm now blogging on juristr.com.

TDD, JUnit 3.8 and JUnit 4

I don't know whether you already got in touch with Unit testing or TDD (Test-driven development). At least you should if you're developing software in a more "professional" manner.
I personally first encountered unit-testing and TDD at the University. Initially you actually don't get the point about it. Ok, I mean, you see that it is necessary and that it should be done, however when you start programming afterwards, testing is always something annoying, something you do because your professor says that is has to be done. You usually want to continue hacking your problem instead to do boring testing. I started to "enjoy" (big quotes :D ) testing mainly when I started to develop larger and more complex applications which I did during one of the last projects at the University and when I developed the application for my thesis project. Initially you force yourself to write the test-cases but once you have quite a lot of features implemented and you have to do large changes (which you have for sure) then you get it why you wrote those tests. If they have been well written they'll save your life since they guarantee that all the previously implemented functions still work also after you performed all the necessary changes. Without tests you cannot identify whether all of the features of your software still work and therefore you will try to avoid with all of you energy any big change to your system (probably disappointing your customers).
What I would like to suggest and which worked quite well for me till now is to proceed in a test-driven development style (TDD, one of the XP practices). A test-driven development cycle usually looks as follows:

  1. Write a test for the next bit of functionality you have in mind. The test should succeed only when the functionality has been implemented correctly.
  2. Make the test compile by creating stubs for all the missing classes and methods referenced by the test.
  3. Run the test. It should fail.
  4. Implement just enough functionality to get the test to succeed (proceed aggressively by hacking the problem).
  5. Clean up the implementation as much as possibly, typically by removing duplication (do refactoring).
As I'm developing a lot in Java, I usually used the JUnit 3.8.1 library within the Eclipse IDE. Recently when I started to develop a new project (I will announce more details after its first release ;) ) I switched to the JUnit 4 library. There are some drastic changes. While the 3.8.1 version was using naming conventions and reflection for locating tests (for which reason it also extended from the junit.framework.TestCase), the new version doesn't extend any class. It uses the annotation mechanism instead. So for instance an old JUnit 3.8 test looked as follows:

import junit.framework.TestCase;

public class TestAdder extends TestCase{
public TestCase(){
...
}

public void testAdd(){
...
}
}

...the same test written for the JUnit 4 framework would look like this

public class TestAdder{
public TestCase(){
...
}

@Test
public void testAdd(){
...
}
}
This has the main advantage is that one is no more bound on naming conventions such as all test-methods have to look like "testFoo()", although I personally didn't found those conventions bad at all.
JUnit 3 test usually call the setUp() method for doing variable initializations, logging and some other stuff before starting the tests and after each tested method the tearDown() method is invoked. In JUnit 4 these methods don't exist any more, but they are - as you probably already mentioned - substituted with the appropriate @Before and @After annotations. In this way you're free to choose your own name for the setUp() or tearDown() method by just adding the right annotation.
Another thing JUnit 3 testers will probably miss is that there is no suite() nor a GUI runner. So what I encountered when writing the new version 4 tests is that the integrated Eclipse JUnit 3 runner clearly doesn't find the tests since they don't dispose of a suite() method. To gain backwards compatibility the TestCase has therefore to be wrapped in a JUnit4TestAdapter (see sample below) such that it can be invoked by the Eclipse JUnit runner.
...
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(FileSystemManagerTest.class);
}
...where "FileSystemManagerTest" has clearly to be substituted with the name of the TestCase.

To summarize I have to say that moving from JUnit 3 takes some time till one gets accustomed to JUnit 4, but as soon as these mentioned differences are known everything remains quite similar. Still tests cannot be automatically reverse engineered from existing source code :D

"Mapplets" on own website: illegal???

Today morning Alex - a friend of mine - wrote me a mail, pointing me to a pcwelt.de article with the header "Die illegalsten Websites der Welt - Teil 1" (engl. transl: "The most illegal websites of the world - Part 1"). The article had the following german content (direct link):

Homepage: Stadtplan einbinden

Darum geht’s: Wer seine eigene Homepage gestaltet, ist vielleicht versucht, einen Stadtplan – etwa als bessere Anfahrtsskizze – einzubauen. Und weil es so einfach ist, holt er ihn sich von einem Stadtplandienst im Internet, etwa Google Maps oder Map 24.

So gefährlich ist es: Das kann teuer werden. Wer ohne Genehmigung des Dienstes eine Karte für die eigene Site verwendet, verstößt gegen das Urheberrecht. Der Streitwert bei Abmahnungen wird generell extrem hoch angegeben, um den Abgemahnten von einem Prozess abzuschrecken. Denn die Anwaltskosten richten sich in der Regel nach dem Streitwert einer Sache.
I'll try to briefly translate its meaning. The article basically says that there are many people around the web which try to integrate a city map or direction sketch on their personal website. In such a case Google Maps or Map 24 offer nice services. (Google) "Mapplets" offer for instance a nice way for adding a small, interactive and personalized Google Map on ones website (see for instance this sample). According to the article however, placing such maps (including the Google ones) on a website without the permission of the map-data-providing service would violate their copyright. This - so the article - could therefore quickly become quite costly for the website owner due to legal fees.

In my eyes the article is wrong or at least not really written clearly when it says (indirectly) that this violation of the copyright holds also for the Google Maps. This would be totally contrary to the philosophy of the Google Map API and the Mapplets. However to be sure I exchanged some e-mails with Pamela Fox (Google Maps Engineer), which also confirmed me that there is no legal issue with the Google Mapplets or API as long as one stays inside their terms of service. Google has the permission from the data provider to allow the use of their maps by others through the API or Mapplets. Moreover there is usually by default a link on the map pointing to the terms of service and the copyright holders. So as long as those links are clearly visible, everything is fine. What could be a problem is when people create screenshots of the map and place only a part of it on their website (as image) without placing a note of the copyright holder.
I did however not inform myself about the legal situation with the Map24 service.

Android - An Open Handset Alliance Project

There have been a lot of rumors around the web recently about an outcoming "GPhone". Actually there doesn't exist any GPhone, but Google launched a system called Android. It is an open mobile phone platform, an Open Source SDK which allows developers to build their own applications. There is a YouTube video on the Google Code Page, which introduces the system. The project's homepage can be found here. I was not able to check out all the details about the project yet (I'm working now so... ;) ). However I've seen that there are detailed instructions for downloading the developer SDK and setting up the development environment (Eclipse).
It will be fun to do some experiments with it, also because I gathered already some experiences and knowledge in mobile programming during the development of my bachelor thesis project. Maybe I'll write something more detailed about Android once I had the time to develop some sample application.

GME starts to appear here and there

It seems as if Google uses their new Mashup editor in many other sites for making them more functional in a quick and easy way. That's also why it probably has been build: to quickly and easily create powerful apps with a lot of functions. For instance the Google Mashup Gallery has actually been build by using the Mashup editor (just take a look at the browsers URL). But also the example gallery of the newly released Open Social API of Google uses the Mashup editor for displaying a gallery of sample applications (actual mashup link). What they do is to import the mashup as an inline-frame on their site.
By the way, what I noticed is that there is no "View source" and "Login" link on the iframe which is placed on the sample applications gallery of the Open Social API gallery as it is automatically done on all created mashups. I discovered that this can be done by faking the application to be a Google Gadget which can be done by adding the attribute gadget="true" in the header-row of the GME application. Below there is for instance the one of my News Mapper application:

<gm:page title="Newsmapper" gadget="true" authenticate="false" css="/css/g.css" class="googleTheme" onload="init()"></gm:page>
This can be very useful as for instance when one wants to host his created mashup on his personal domain or another website than [project-name].googlemashups.com (as it is done by Google itself on the Open Social page). In such a case the "View source" and "Login" link on the top-right corner would be disturbing in the iframe. Actually the "external hosting" on a personal domain could be a desirable future feature of the editor.
Anyway I recommend to leave the "view source" link where it is or to put it at least on some other place on your application (btw I placed it under the about section of my mashup). This can be done by just creating a link to the index.gml or any other source-file of the mashup that should be displayed. The GME's philosophy is to share the source code with others, wherefore there is also by default the "View source" link on every mashup. I think this should be respected, also because these apps are not that world-changing such that one gets rich with them :) . By letting the source open, others can learn. Copying is bad, but learning from existing code from others and improving those solutions or taking over parts of it (in this case you should credit the original author by placing his name + link etc) helps everybody.