Rash thoughts about .NET, C#, F# and Dynamics NAV.


"Every solution will only lead to new problems."

Sunday, 22. January 2012


F# Legacy: Test implants

Filed under: F# — Steffen Forkmann at 11:51 Uhr

Legacy code is a problem in all languages, even F#. Zwinkerndes Smiley

The super awesome Ilker Cetinkaya published an excellent article about “test implants”. I really recommend to read his post before you read this one. It’s a really well written story called “The quest of the test”.

I destilled his nice little story to this small F# code:

We have a function a that is part of a third-party API and a function b which is part of our own legacy code base. The problem is: we want to check that b has called a. without changing b’s signature. Ilker suggested to use a “test implant”. Let’s try to do something similar with our small F# code. Since we are in the land of functional programming our idea is to implant another function into b. So let’s rename b into b’ and add the implant to the parameter list of b’.

Of course we restore b’s behaviour by utilizing b’:

As you can see, we didn’t change the signature nor the behaviour of b. This is a typical refactoring in F#. The program runs as before. Now we want to write our test:

I hope you can see the similarity between this and Ilkers solution. The only difference is that we don’t use new constructors here. I really like this since it brings you one step further to nice functional design. What do you think?

Tags: , , ,

Monday, 16. January 2012


Building FAKE scripts with Jenkins

Filed under: F#,FAKE - F# Make — Steffen Forkmann at 16:11 Uhr

Jenkins is an extendable open source continuous integration server. In this blog post I show you how you can build FAKE’s Calculator sample with Jenkins. If you are familiar with Jenkins or Hudson then this should be straight forward.

Install Jenkins

Go to http://jenkins-ci.org/ and download/install Jenkins. In addition install the following plugins:

Create a new Task

Create a new “free-style” task in Jenkins:

image

Use git as the Source Control Management tool and configure the repo as following:

image

Configure the build step to run FAKE from the command line:

image

And finally configure the post build actions:

image

Running the build

If everything is setup correctly, then you should be able to start the build from the project page:

image

The output should look similar to this:

image

Tags: , , ,