Good unit tests are supposed to be self-contained so that they can be run in a stand-alone fashion independent from other tests. So much for theory. In practice, unit tests sometimes develop unwanted relationships with each other that cause one test to unknowingly depend on another test’s prior execution or lack thereof. This article will shed some light on possible causes of such dependencies, strategies for early detection and mitigations using the example of JUnit tests executed through Maven’s popular Surefire test runner plugin.
Lesen Sie den restlichen Eintrag »
Order Matters – When Unit Tests Develop Unwanted Relationships
Mittwoch, 14. März 2012
Caching Hibernate Entity Collections Considered Evil
Dienstag, 13. März 2012
Performance is hard, i.e., when tuning a client-server application for speedy response times and handling a sufficient number of concurrent users, expect pitfalls. One of these pitfalls will be outlined in this article: The attempt to use caching through Ehcache with Hibernate entities.
Lesen Sie den restlichen Eintrag »
Vortrag “Java Concurrency” – Folien verfügbar
Sonntag, 14. August 2011
Die Folien des Vortrags “Java Concurrency” von Thilo-Alexander Ginkel bei der majug² – Java User Group Mannheim stehen nun zum Download zur Verfügung.
Building Android Maven Projects With Eclipse
Freitag, 1. Juli 2011
Using Maven for your Java build needs is generally a good idea as it provides automatic dependency management and self-contained, reproducible builds. For builds of Java EE applications, this has already become a de facto standard.
However, Maven is a command-line based technology, which does not provide any out-of-the-box integration with modern IDEs such as Eclipse. Fortunately, there is the m2e project, which adds Maven project support to Eclipse.
To build Android projects, a special Android Maven plugin is required. Unfortunately, using this build plugin does not yet provide support for importing the resulting project into Eclipse using m2e. Fortunately, there is the m2eclipse-android-integration plugin, which fills this gap and integrates the mavenized Android build with Google’s ADT for Eclipse.
Due to the recent transition of m2e from Sonatype to the Eclipse foundation, the current (as of 2011-07-01) m2eclipse-android-integration plugin is, however, not compatible with the Eclipse m2e 1.x plugin. Instead, it requires an older version (0.12.x), which is fortunately still available at Sonatype’s update site. Follow these instructions to set up your Eclipse environment:
Prerequisites: Eclipse 3.6.2 (Eclipse 3.7 is untested and supposedly already ships with m2e pre-installed, so you may have to wait for a compatible m2eclipse-android-integration version) with a current version of Google’s ADT installed.
- In Eclipse, go to “Help” | “Install New Software…”
- In the “Work with” dropdown, add the Sonatype m2e update site:
http://m2eclipse.sonatype.org/sites/m2e - Select the “Maven Integration for Eclipse (Required) – 0.12.1.20110112-1712″ entry for installation
- When prompted, restart Eclipse
- Open “Help” | “Install New Software…” again
- Enter the m2eclipse-android-integration update site:
https://svn.codespot.com/a/eclipselabs.org/m2eclipse-android-integration/updates/m2eclipse-android-integration/ - Select the “Maven Integration for Android Development Tools – 0.2.5″ entry for installation
- When prompted, restart Eclipse a second time
The Android Maven integration for Eclipse should now be operational. Next, go ahead and import your Android project into Eclipse by Choosing “File” | “Import…” | “Maven” | “Existing Maven Projects”. Note that this will only work if you have already defined a pom.xml for your Android project. Instructions on setting this up are available in the maven-android-plugin documentation.
That’s basically it. In some cases the imported project may be created with incorrect Java Compiler settings, which will cause ADT to emit an error message such as:
Android requires compiler compliance level 5.0. Please fix project properties.
To fix this, right-click on the project node in the Project Explorer and select “Android Tools” | “Fix Project Properties” from the context menu or manually set the JDK Compliance of the project to 1.5 or 1.6.
That’s it, have fun!
Vortragsankündigung: “Java Concurrency” in Mannheim
Donnerstag, 16. Juni 2011
Am 11. August 2011 wird Thilo-Alexander Ginkel bei der majug² in Mannheim einen Vortrag zum Thema “Java Concurrency” halten:
Ein Sprichwort besagt: “Concurrency is hard to get right”. Trotzdem wird es gerade in Zeiten von Multi-Core-CPUs immer wichtiger, die Parallelisierbarkeit von Software nicht außer Acht zu lassen.
Der Vortrag illustriert anhand anschaulicher Beispiele typische Probleme, die bei der Entwicklung nebenläufiger Software auftreten. Im Anschluss geht er näher auf die Werkzeuge ein, die uns Java zur Lösung dieser Probleme an die Hand gibt – nicht jedoch, ohne diese einer kritischen Betrachtung zu unterziehen. Er schließt mit einem Überblick über neuartige Konzepte für die Parallelisierung von Software wie Software Transactional Memory und Actors.
Details zur Veranstaltung gibt es online auf den Seiten der majug² unter: http://jug-mannheim.mixxt.de/networks/events/show_event.42340
Developer Productivity: Git / Bash Integration
Freitag, 10. Juni 2011
Git, a distributed revision control system, is steadily gaining momentum. For beginners, Git typically comes with its unique challenges, which we will probably address in a separate post. On the other side, Git comes with plenty of customization and integration options due to its excellent scriptability, which are a major plus in terms of developer productivity.
This post will outline how to activate one of those gimmicks: Tweaking the bash prompt to enable displaying information about the current Git repository, such as the current branch or whether there are any dirty (or untracked) files. These instructions are based on the assumption that you are running a recent Ubuntu release, such as the current Ubuntu 11.04. Ubuntu 10.10 will also do the trick, while the status of Ubuntu 10.04 is currently unknown to the author. The procedure for other Linux distributions (especially Debian) should be similar.
First, make sure that you have the git package (which may be named git-core for your distribution version) installed and also install the basic bash-completion package. While bash-completion is active on Ubuntu by default, you need to manually enable it on Debian by adding the following snippet to /etc/bash.bashrc, which is used by bash to initialize interactive shell sessions (in contrast to /etc/profile for non-login shells):
# Check for interactive shell.
if [ -n "$PS1" ]; then
if [ $bmajor -eq 2 -a $bminor '>' 04 ] || [ $bmajor -gt 2 ]; then
if [ -r /etc/bash_completion ]; then
# Source completion code.
. /etc/bash_completion
fi
fi
fi
unset bash bminor bmajor
Once this is in place, we are ready to enable Git integration. First, you will need to decide if you would like to enable that tweak just for the current user or whether you would like to enable it globally (chances are good that you will not notice any difference for a single-user system). In this configuration example, we will take the local route. If you would like to activate the tweak globally, just make the changes in /etc/bash.bashrc instead.
So, let’s get started: What is displayed as the bash prompt is determined by the current setting of the PS1 variable. On a stock system that may read:
PS1='\u@\h:\w\$ '
To figure out your system’s default, type
echo ${PS1}
at the prompt.
To enable Git integration, we will override the default setting by adding the following line to ~/.bashrc:
PS1='\u@\h:\W$(__git_ps1 " (%s)")$'
If you would like to get an indicator (“*”) for dirty changes, set the GIT_PS1_SHOWDIRTYSTATE variable as in:
GIT_PS1_SHOWDIRTYSTATE=1
Further available options are:
- GIT_PS1_SHOWSTASHSTATE: Shows an indicator (“$”) for a non-empty stash
- GIT_PS1_SHOWUNTRACKEDFILES: Shows an indicator (“%”) for a untracked files
That’s basically it. Save your changes to .bashrc and open a new shell. When changing into a directory hosting a Git repository, you should see the enhanced prompt as in (note the branch specification in braces):
user@host:dir (master)$
If you like things a bit more colorful, you may prefer this variant:
PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\W\[\033[01;33m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
Enjoy!