Skip to content

Commit

Permalink
All old blog post have decent excerpts for the index
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Jan 3, 2015
1 parent 84dabba commit f3246a3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions _posts/2010-02-13-experimenting-with-theories.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ categories: [JUnit]

The very first 4.x release of JUnit contained support for custom test runners. Moreover, it came with the `Parameterized` test runner that allows to execute the test cases in a test class against a collection of values, i.e. parameters.

<!--more-->

The example that comes with the Javadoc of the `Parameterized` class tests an imaginary Fibonacci calculator for a number of data points:

{% highlight java %}
Expand Down
2 changes: 2 additions & 0 deletions _posts/2010-02-16-generic-matcher-pitfalls.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Using [Hamcrest](http://code.google.com/p/hamcrest/) matchers in combination wit

Recently, while working on the backend of [Project Usus](http://projectusus.org/), we needed a simple matcher, that would test whether a given set is empty. At the time, we reused a set matcher we had already written a few minutes earlier.

<!--more-->

Today, I had another look at the pre-defined matchers that come with Hamcrest and found the `empty()` matcher in `org.hamcrest.Matchers`. Since I'm not concerned with the actual implementation (at least for now), I'll just give you the factory method:

{% highlight java %}
Expand Down
2 changes: 2 additions & 0 deletions _posts/2010-03-13-applying-dry-to-junit-categories.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ A category marker is simply a class or interface, e.g.
public interface SlowTests {}
{% endhighlight %}

<!--more-->

Tests can be marked using the `@Category` annotation:

{% highlight java %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ categories: [JUnit]

In a recent [commit](http://github.com/KentBeck/junit/commit/f09cff79b941a525271f3f2838a9742b4c5c8d36) to JUnit Kent Beck and David Saff have added an "alpha-ready implementation of `SuiteBuilder`". As Kent Beck previously described in a [blog post](http://www.threeriversinstitute.org/blog/?p=456), the idea behind the `SuiteBuilder` runner is to use annotations on fields instead of annotations on classes.

<!--more-->

### Limitations of regular test suites

While an annotation can take parameters the arguments must be literals, e.g. constant String values or class literals. For example, the classic `Suite` runner is configured using the `@SuiteClasses` annotation that takes an array of class literals, i.e. the test classes to be run:
Expand Down
10 changes: 7 additions & 3 deletions _posts/2010-11-16-primitive-matt-ch-ers.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ categories: [JUnit, Hamcrest]

The [Hamcrest project](http://code.google.com/p/hamcrest/) provides a large number of matchers, i.e. declaratively defined predicates. Prominent uses of these matchers include testing and mocking libraries like JUnit and jMock, respectively.

### How to use them?
One of the benefits of using `assertThat()` and Hamcrest matchers is that assertions become very readable. Unfortunately, you often have to rely on a questionable Java mechanism: auto boxing/unboxing.

<!--more-->

### How to use matchers?

So, here is a very simple example of how to use a matcher:

{% highlight java %}
@Test
Expand All @@ -17,8 +23,6 @@ public void onePlusOneIsTwo() {
}
{% endhighlight %}

While the above example is simple, it demonstrates one of the benefits of using `assertThat()` and Hamcrest matchers: assertions become very readable. Unfortunately, you often have to rely on a questionable Java mechanism: auto boxing/unboxing.

Auto boxing and unboxing have been introduced in Java 5 to ease the use of primitive types and their counterparts: *real* objects (a.k.a. reference types). However, especially unboxing can lead to hidden NullPointerExceptions and thus is discouraged by many developers. For details see [Autoboxing is Evil](http://pboop.wordpress.com/2010/09/22/autoboxing-is-evil/) by Nicole Rauch and Andreas Leidig.

For this reason, the Eclipse Java compiler optionally shows warnings whenever boxing or unboxing occurs. While it is certainly a good idea to enable this warning, it also puts markers on code that is perfectly sane, like the test case above. To prevent un-/boxing and use matchers at the same time, one can go back to pre-Java 5 times and convert the
Expand Down
4 changes: 2 additions & 2 deletions _posts/2012-03-19-using-dbunit-without-xml.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ In the [previous post](/blog/2012/03/13/database-tests-with-dbunit-part-1/) we h

Now, you can think about XML what you want but I (and hopefully most people) would rather not want to write such files but instead create the dataset directly in the code of the test class. As it turns out, this is very hard using plain DbUnit.

<!--more-->

## DataSetBuilder to the rescue

So, I thought, wouldn't it be nice to have a builder for datasets with an easy-to-use API? Thus, I sat down and wrote [DataSetBuilder](https://github.com/marcphilipp/dbunit-datasetbuilder) for DbUnit.

<!--more-->

Here's how it can be used to replace the `dataset.xml` file from above:

{% highlight java %}
Expand Down
2 changes: 2 additions & 0 deletions _posts/2012-06-11-interview-with-uncle-bob.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ A couple of weeks ago I had the pleasure to participate in [Uncle Bob](http://ww

In the meantime, the interview has been published in print in the [VKSI Magazine](http://www.vksi.de/fileadmin/downloads/magazin/VKSIMagazin_6.pdf) (PDF, German) and as a video on [YouTube](http://www.youtube.com/watch?v=OIHvp7WzuH0).

<!--more-->

<iframe width="560" height="315" src="http://www.youtube.com/embed/OIHvp7WzuH0?rel=0" frameborder="0" allowfullscreen></iframe>
2 changes: 2 additions & 0 deletions _posts/2012-06-23-pecha-kucha-software-craftsmanship.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ categories: [Software Craftsmanship]

A little more than a month ago I spoke at the [Entwicklertag](http://entwicklertag.de/) in Karlsruhe about Software Craftsmanship. More precisely, I gave my very first Pecha Kucha on my understanding of the principles and ethics behind it. Along with [several others](http://www.youtube.com/user/andrenaobjects), my talk was recorded and is now available on [YouTube](http://www.youtube.com/watch?v=oljTjizjKdM).

<!--more-->

<iframe width="420" height="315" src="http://www.youtube.com/embed/oljTjizjKdM?rel=0" frameborder="0" allowfullscreen></iframe>

Since the slides are a little hard to see in the video, I have uploaded them to [SpeakerDeck](https://speakerdeck.com/u/marcphilipp/p/pecha-kucha-software-craftsmanship).
Expand Down

0 comments on commit f3246a3

Please sign in to comment.