« Change an Organization Like a Startup?| Main | The Hat »
Setting up F# for TDD with xUnit
"You've got to be very careful if you don't know where you are going, because you might not get there. " - Yogi Berra
Some things are so easy they're idiot-proof, but then along comes a better idiot to prove you wrong.
I was thinking about this today as I set up Visual Studio, F#, and Xunit
Since I thrashed around for about an hour and shouldn't have, I thought I would make an easy 1-2-3 cookbook for setting up F# and TDD.
Step 1: Download the latest version of XUnit

I prefer XUnit.NET over NUnit
Step 2: Create a new F# Application
Step 3: Add a file to put your tests in (not strictly necessary)

Separating tests and the rest of your code is just good practice
Step 4: Add a reference to the XUnit dll

It's a small file, weighing in around 64K
Step 5: Setup the hotkeys and external tool item for xUnit

Good use of hotkeys and macros make coding faster.
It's the little stuff like this that adds up over time
Step 6: Write the shell of the method you're starting

Even with test-first, you gotta have something to bounce your tests off
Step 7: Write your tests

I like the xUnit syntax and structure much better than NUnit's verbosity
Step 8: Code!
I had a little problem with the dlls not copying over to the right folder, so I manually copied them. Actually I just dumped the whole xUnit directory over into my build area. I also thrashed around with making my tests public, but it wasn't necessary. Using the output window is an okay way of getting results, but I like big green lights when I code, so the xUnit GUI is more my speed.
I also had to explicitly include both XUnit and the program file at the top of the tests file. F# is sensitive to compile order and indentations -- easy to get stalled a little when picking it up after a break.
There -- next time should be a lot easier!
Leave a comment