
I stumbled across a link to Glen Alleman’s blog from a post on the Agile Project Management list today. He has an excellent post describing the FBI’s virtual case file project, it’s spectacular failure, and rebuttals to a lot of posts over the past few days to several agile lists asking if agile processes could have saved it.
In particular, several key things stood out to me about the project:
A very good read, and a blog I will definately be subscribing to.
Fitnesse has a nifty feature where you can store the output of one test table in a symbol that you can then use in a subsequent table. The documentation does a good job explaining the concepts, but seems to be missing some code behind the scenes to make it work. So I’ve put together a simple example of using it.
One thing to note is that this feature is implemented in the various version differently, which is why this is targetted at the Java Fitnesse version.
Let’s say we have one class that returns a value (SymbolTextFixture) we need to use in a subsequent test (SymbolTestRecall). First, let’s look at our value provider:
import fit.ColumnFixture;
public class SymbolTestFixture extends ColumnFixture {
public SymbolTestFixture() {
super();
}
public String getTestValue() {
return "Set from Fixture!";
}
}
So, we have a class whose instance provides us some value. Now, we have a class that needs to take in this value so it can display it:
import fit.ColumnFixture;
public class SymbolTestRecall extends ColumnFixture {
public String testValue = "Not Set";
public SymbolTestRecall() {
super();
}
public String getTestValue() {
return testValue;
}
}
So, obviously our goal is to get the test value from a SymbolTestFixture instance into the testValue field of SymbolTestRecall, so it’s getTestValue() method can display it.
As mentioned above, there is a special header syntax within ColumnFixtures that let you save the output from a method into a symbol, which can be reused later. Here’s the Fitnesse fixture we’d use for this:
|Symbol Test Fixture|
|=getTestValue?|
|myKey|
The above test is saying to use a class called SymbolTestFixture to store the output of the getTestValue method into the symbol myKey. How does it know to do that? The = in front signals to store the value, and the ? at the end tells the Fit runner that the value will be coming from a method.
So now that we have the value in myKey we want to use it. This test shows that:
|Symbol Test Recall|
|test Value=|getTestValue?|
|myKey|Set from Fixture!|
This test says to use an instance of the SymbolTestRecall class and set the testValue field with the value stored in the symbol myKey. It then verifies that the value returned from the getTestValue method is the value returned from our previous test (“Set from Fixture!”).
And there you have it! The complete Fitnesse test looks like:
!path /home/foyc/workspace/fit_stuff/bin
|Symbol Test Fixture|
|=getTestValue?|
|myKey|
|Symbol Test Recall|
|test Value=|getTestValue?|
|myKey|Set from Fixture!|
The above just adds the !path directive to where the output of my classes are. Build your classes, fire up your Fitnesse server, and test to green goodness!
Excellent advice on building frameworks and libraries from John Roth, via the XP mailing list:
Reuse is an interesting issue. There’s a rule of thumb that you should write it three times, then you’re in a position to make a resuable library or framework the fourth, because you now know what you need; you’re not speculating.
For the fourth time, if you simply take the first three and remove duplication you might even get it done faster that doing it separately.
That’s certainly been my experience. Try to make a tool reusable too early, without having gone through iterations with it, and it rarely works well without modifications. But take something you’ve done several times, pull out the common components, remove the duplication, and you might just have something there.
It’s one of the great things about Rails. It came from a real project, with real needs, and was really solving them.
Microsoft employees are excited about OS X…, at least according to the comments (350 and growing!) on this blog entry entitlet Vista 2007 – Fire Leadership Now.
This is what worries me about large companies. Microsoft used to be touted as the place to be. It doesn’t seem like that anymore – now Google might be the place to be. But they’re public now, and so they serve different masters. When the shareholders begin to run the company…
But then, I don’t want to believe that you can’t grow a company without turning it into a mess. Of course, you are going to have some politics, but with the proper leadership and focus people should be able to come together. Or, by drastically moving from the norm, as Richard Semler did with Semco (here’s Geoffrey Slinker’s paper on Semco).
In fact, the only large company I’ve read of so far that has been around for a long time and seems to have it right is 3M, a frequent example from books like Lean Software Development. Project champions, being able to understand the market, and ROI, and customers, and consistantly delivering on that.
Maybe 3M should start a consulting business. Maybe larger companies should pay attention to it.
Something so simple, yet so seemingly undocumented…
After struggling for about 10 minutes with trying to clear a TkCanvas from Ruby, and only finding what seemed to be one message discussing it (but not answering it), I stumbled across the answer – delete('all').
So, if I have a canvas like this:
def initialize(parent)
@parent = parent
ph = { 'padx' => 10, 'pady' => 10 }
clear_b = TkButton.new(parent) { text 'Clear'; pack(ph) }
clear_b.command{clear}
exit_b = TkButton.new(parent) { text 'Exit'; pack(ph)}
exit_b.command{ exit }
@canvas = TkCanvas.new(parent)
@canvas.pack
@start_x = @start_y = 0
@canvas.bind("1", lambda {|e| do_press(e.x, e.y)})
@canvas.bind("B1-Motion",
lambda {|x,y| do_motion(x,y)}, "%x %y")
@canvas.bind("ButtonRelease-1",
lambda {|x,y| do_release(x,y)}, "%x %y")
end
I can use this as the clear method to wipe the canvas:
def clear
if @canvas
@canvas.delete('all')
end
end
Easy as pie! ;)
self.out
(Update: James updated his blog entry with a list of resources to good D/I articles [here and here] which discuss much better the topics below.)
James Shore has a new post about Dependency Injection, which he calls a “25-dollar term for a 5-cent concept.”
While his examples were indeed examples of D/I, he seems to miss a critical one, the ability to use Spring and Spring.NET to inject dependencies at runtime using configuration files. He has a code snippet that looks like:
public class ExampleTest {
TestDoStuff() {
MockDatabase mockDatabase = new MockDatabase();
// MockDatabase is a subclass of DatabaseThingie, so we can
// "inject" it here:
Example example = new Example(mockDatabase);
example.DoStuff();
mockDatabase.AssertGetDataWasCalled();
}
}
public class Example {
private DatabaseThingie myDatabase = new DatabaseThingie();
public Example(DatabaseThingie useThisDatabaseInstead) {
myDatabase = useThisDatabaseInstead;
}
public void DoStuff() {
...
myDatabase.GetData();
...
}
}
While it is true that the above is a form of dependency injection, so is the following:
The above is a sample configuration file from a good article on Spring.NET in MSDN Magazine.
So, D/I isn’t just about passing in a dependency via a constructor at compile time. It’s about decoupling your code using interfaces so that you can inject completely different implementations at run-time using configuration.
Of course, Spring.NET is much more than that. You can initialize object graphs, set properties in objects, and initialize singletons, all from a config script.
Oddly enough, the one use James hits on – testing – is the one that I don’t use frameworks like Spring.NET for, and one where his interpretation of being able to pass mocks in from the tests is very valid. But to say that D/I is a 5-cent concept because you can pass in a dependency via a constructor at compile time is similar to saying Rails is only a rapid environment because it is dynamically typed. While both statements are technically correct, they miss a vital concept – configuration based injections with D/I, and metacoding with Rails.
A few weeks ago, several coworkers and I went to the No Fluff Just Stuff Conference (overviews here, here, and here.) During the conference, I got to hear Dave Thomas speak about the Dreyfus Model for Skills Acquisition. A lot sounded familiar, and that was because Dave touched on a lot of the same points Andy Hunt did when he spoke at a CharJUG event in Charlotte.
For those not familiar with the Dreyfus Model, it is a model of skills acquisition that describes how people progress in their knowledge. There are five levels to the model, summarized as:
During the talk, Dave challenged us to an experiment. He asked us to watch closely over the next few weeks the conversations we have. When we are involved in a discussion, mark on each participants head a number in (imaginary!) magic marker which is the Dreyfus level you think of them at. Also put a (imaginary!) number on your head of your own Dreyfus level. Then, tailor the conversation to that. If you are the lower number one, bring the conversation to your level. Conversely, be sure you aren’t talking over the heads – and needs – of the other participants.
The very next week I was working with my pair on some PL/SQL unit tests, which I had very little experience with. One of our development DBAs offered some advice which got us past this problem we were having. He then suggested that it might be a good idea to test another part of the procedure we were working on. But, he wanted us to make the decision of whether we should test it ourselves. After going back and forth for a minute or two of whether we should do it, the Dreyfus model experiement popped into my head. I immediately realized he was at least a four, and I was a one (at most).
Recognizing the situation, I turned to him and said, “I appreciate the teaching style you are using to get us to understand this problem. However, right now, I just need to be told what to do.” Immediately he understood where we were at, and explained his reasoning behind what he was asking about. This enabled our pair to follow a specific path and acheive a win, while understanding a little more about the system at hand.
I challenge you all to do the same. In your conversations with your coworkers, think about what they – or you – need out of it based on the Dreyfus model, and tailor the conversation to it. You might just find yourself getting your points across clearer and faster.
Links:
So, let’s pretend you are happily coding along in C#, doing test-driven development, and you get to a method that needs to return a message that spans multiple lines. Say, an address printer that prints out like:
Cory Foy
12345 Developers Way
Columbia, MO 12345
So what is the test you should write? How about:
[Test]
public void printAddressSpansThreeLinesWhenOneAddressLine()
{
string expected = "Cory Foy\r\n12345 Developers Way\r\nColumbia, MO 12345";
Assert.AreEqual(expected, customer.printAddress());
}
or maybe:
[Test]
public void printAddressSpansThreeLinesWhenOneAddressLine()
{
string expected = @"Cory Foy
12345 Developers Way
Columbia, MO 12345";
Assert.AreEqual(expected, customer.printAddress());
}
The problem is that while both of the above styles are valid C# syntax, they will both fail – on Linux.
“Linux?!”, you gasp!
Yes. There really is quite a push with Mono to get a lot of C# apps running on Linux. The problem is that if you rely on a newline being “\r\n” as it is on Windows, your apps aren’t portable for no other reason then you didn’t know about the difference or didn’t want to bother with it.
The correct solution, which is cross platform and really not that difficult, is:
[Test]
public void printAddressSpansThreeLinesWhenOneAddressLine()
{
string expected = "Cory Foy" + System.Environment.NewLine
+ "12345 Developers Way" + System.Environment.NewLine
+ "Columbia, MO 12345";
Assert.AreEqual(expected, customer.printAddress());
}
The same applies for path separators. On Windows, it is “;”. On Linux, it is “:”. And, just like NewLine, Microsoft has a System.IO.Path.PathSeparator. They also have a System.IO.Path.DirectorySeparatorChar for directory structures.
The tools are there, and not terribly difficult to use. Give it a try and help make your app cross-platform.
Brian Button officially announced the St. Louis Code Camp coming up May 6th and 7th. I know Brian has worked hard to bring it here. I spoke at the Charlotte one, and had great fun. It isn’t often you get to go directly into a Microsoft campus and talk about open source tools, and even Java and Ruby, but that’s exactly what happens here.
Brian is looking for Speakers and Volunteers, so if you are interested be sure to get a hold of him.
CARFAX’s own Gary Brown has gotten together a group of XP enthusiasts to form the Mid-Missouri XP User’s Group. The first public meeting is tonight at the CARFAX offices in Columbia, MO. Several people who attended the NFJS Conference in St. Louis, myself included, will be doing a panel discussion on various topics, including the latest from the Java world and Ruby.
It looks to be a great time, and hope anyone in the area can make it out. Here was the official annoucement:
The March 2006 meeting of the Mid Missouri XP User Group will be held on Tuesday, March 14, 6:00 – 8:00PM, at the CARFAX office in Columbia. Pizza, salad, and pop will be served.
This month, several CARFAX employees attended the No Fluff – Just Stuff conference in St. Louis. They returned full of enthusiasm about the new technologies and techniques that they learned about at the conference.
For our program this month, Steven Asher, James Carr, Cory Foy, Jami Fulton, and Chris Sage will lead a panel discussion about their experiences at NFJS. They will discuss many new technologies and techniques that should be on everyone’s radar screen.
Please RSVP by noon on 3/14, so we can order the appropriate amount of food.
See you there,
Gary Brown
CARFAX XP Coach
(573) 356-7581CARFAX, Inc.
2301 Maguire Blvd
Columbia, MO 65201