The long way through Software Craftsmanship

Searching on a suite of failing tests

Aug 13, 2015 - 5 minute read - Comments - tipsearchnaive-searchbinary-searchdichotomous-searchcomparisonspringcontextend-to-end-testtest-dependencyantipattern

Motivation Today, at a client, in the green phase, we had a test suite which was failing: the whole suite fails but the test cases, individually, succeed. So my first impression was that something was being shared between tests. Also confirmed because the failing class was an EndToEnd test, in which we load the whole spring context A quick glance was not revealing anything interesting, so I decided to find which is the minimum suite (as opposed as to the whole suite) that makes the new testcase fail, expecting to narrow the search for possible causes.

The Animal Laborans and the Homo Faber

Aug 10, 2015 - 2 minute read - Comments - the-craftsmanrichard-sennettphilosophyhannah-arendtquoteanimal-laboranshomo-faber

I’ve found this quote very interesting from the book “The Craftsman”, by Richard Sennett: Animal laborans is, as the name implies, the human being akin to a beast of burden, a drudge condemned to routine. Arendt enriched this image by imagining him or her absorbed in a task that shuts out the world, a state well exemplified by Oppenheimer’s feeling that the atomic bomb was a “sweet” problem, or Eichmann’s obsession with making the gas chambers efficient.

The language was prepared for that

Aug 10, 2015 - 2 minute read - Comments - clojurehaskelljavalanguage-comparisonprefix-notationoperatoroverloading

Many times I’ve written this function: public boolean between(int lowerBound, int n, int upperBound){ return lowerBound <= n && n <= upperBound; } It may depend on the case, whether it is [], [), (] or (), to use mathematical terms. When the two comparisons are the same ([] and ()), there is duplication in the comparisons. Investigating a little bit on this in clojure, I’ve found this function: <= And its clojuredocs: Returns non-nil if nums are in monotonically non-decreasing order, otherwise false.

Recognizing dependencies

Aug 8, 2015 - 1 minute read - Comments - chapterpoodrsandi-metzrubydependencyobjectquote

From the Chapter 3, Managing Dependencies, from the book Practical Object-Oriented Design in Ruby, by Sandi Metz: An object has a dependency when it knows: The name of another class. […] The name of a message that it intends to send to someone other than self. […] The arguments that a message requires. […] The order of those arguments. […] If an object knows any of these facts about another object, it has dependencies to the other.

Multiple return values in a Mockito Stub

Aug 7, 2015 - 1 minute read - Comments - mockitotipstubjava

I’ve been asked today how to return multiple return values from a Mockito Spy, effectively using the spy as a Stub, as well. package com.example.spike; import static org.hamcrest.MatcherAssert.assertThat; import static; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import org.junit.Test; import org.mockito.Spy; public class DifferentReturnValues { @Spy private Spike1 spike1 = new Spike1(); @Test public void spike1() { spike1 = spy(spike1); when(spike1.getBool()).thenReturn(false, true); assertThat(spike1.getBool(), is(false)); assertThat(spike1.getBool(), is(true)); assertThat(spike1.getBool(), is(true)); assertThat(spike1.getBool(), is(true)); } private class Spike1 { public boolean getBool() { return true; } } } The key line is: