Gáspár Nagy on software

coach, trainer and bdd addict, creator of SpecFlow; owner of Spec Solutions

DevCamp09: Behavior Driven Development Applied in Unit Testing

by Gáspár on October 15, 2009

Session startup slide The presentation material (slides and demo source code) of my DevCamp09 presentation are on-line now and can be downloaded from the TechTalk website here.

The downloadable material also contains the framework that can be used to write BDD-style unit tests. This framework will most probably be joined to SpecFlow, the open-source BDD tool we have just launched (hence, the new namespace, TechTalk.SpecFlow.UnitTesting).

Session Abstract

Developer life was good in the golden age of the waterfall: big upfront designs left no surprises for later implementation, code documentation was a piece of cake as nobody else read it anyway, and testing was something developers just heard of remotely through a department called “QA”.The

But things have changed for the worse with the rise of agile methodologies: designs are ruined by requirements coming in weekly and code that was already working perfectly suddenly breaks. Now, business wants to collaborate directly and is interested in details of the implementation, meaning that documentation can no longer be kept on the back burner. And QA is asking for a high coverage of unit tests out of the blue, causing big overheads to write and maintain them with all these ongoing changes.

However, a lot of concepts have been introduced that promise to ease the pain: IoC helps us reduce dependencies in the code, BDD helps us focus on the next functionality to deliver, TDD helps us structure code for testability and Fluent Interfaces are a way of building DSLs that help us communicate with business.

This talk will show how we put these concepts into practice in a project that followed an agile methodology. We’ll show how IoC helped us stay flexible, and how we structured our unit tests in a way that described the expected behavior and could also be understood by business. The source code of the supporting infrastructure we built will be made available to you after the talk as a download.

Screenshots from the demo

image

Execution result of a very simple BDD-style unit test

image

…and the unit test itself

image

Execution result of a more complex BDD-style unit test

image

…the unit test…

image

…and finally the implemented code

Doing it right

by Gáspár on April 20, 2009

I’m a software developer. From time to time, I come to the question why it is good to be a developer? Why is it good to write software?

I don’t have the ultimate answer yet, but I already have a few: making someone’s work easier; to able to get out more value from the things we know; because it is a joy for me; because I can teach other developers to find this joy; or simply because it provides a reasonable good salary. (I always pick the one that fits best to my mood, but honestly I can also argue with each of them.)

I’m not working on software that saves lives directly, and there was a time when I was very sad about that. But then I have realized that the world is full of people that also don’t do that, still you can be very happy that they do what they are doing. (Now I cut the long list of examples, because I tend to be too sentimental.) The point is that you are happy with them because they do their job right.

Today I have found the website of the TED community. TED stands for Technology, Entertainment, Design, and it is a community (and a yearly conference) where people try to bring these concepts together and make something remarkable. It is innovative, but not necessarily technology-wise. And very-very inspiring. The best talks from the conferences are also available on-line, so you should better look at them. They are all relatively short (the allowed time for a speech is 18 minutes).

Why does this come here? Because sometimes you have to step back and look at things from a broader perspective in order to step further or gather new ideas. Here are some:

Matthew Childs: Hang in there! 9 life lessons from rock climbing

You will start listening to this as it would be about rock climbing, but you’ll soon realize that this is also about you (and for example software development). (04:48)

Scott McCloud: Understanding comics

As you’ve guessed this is also about more than comics. It is about vision and about finding ways to understand things (take it apart and put it together). About how technology and art can cooperate with each-other. (In this sense, it can be also helpful for software usability.) And last but not least to show how to make a memorable presentation. (17:08)

In McCloud’s talk, there is an interesting list of rules which I have to think of:

  • Learn from everyone
  • Follow no one
  • Watch for patterns
  • Work like hell

I have learned a lot today.

Scripting database including data in SQL Server 2008 Management Studio

by Gáspár on March 18, 2009

I was always missing a function in the management studio of the different SQL Server versions. This was to generate a script from an existing database, that also contains the INSERT statements for the existing data in the tables.

Today I have found out, that there is already such a feature in the Management Studio of SQL 2008, although it is not so easy to find it.

Actually it is very simple. You only have to use the “Generate Scripts” wizard, and on the options step, you have to enable the “Script Data” option somewhere at the end of that long list.

wizard options

Enable WCF hosing in IIS 7

by Gáspár on January 18, 2009

Update: there is an updated version of this post: Enable .NET 4.0 WCF hosing in IIS 8

As I was playing with WCF services on Windows 7, I had to set up IIS to host a WCF service. It turned out that it is not as straightforward as I expected. Here is a small summary about the steps that you have to do. (I have found a post of Pandurang Nayak that describes these steps, but that article is not available currently, only through Live Search cache).

  1. Don’t forget to install IIS… :) Yes, it took me some time to realize that it is not installed by default.
  2. When you install IIS (Contol Panel / Programs / Turn Windows features on or off), the sub-components selected by default are not enough. You need at least the Windows authentication, the IIS 6 Management Compatibility (for Visual Studio) and probably some more, but I gave up playing with the sub-components and finally selected all.
    Don’t forget to restart your machine. Although you are not asked to do that, for me it did not work.
    image
  3. Still in the “Turn Windows features on or off” dialog, you have to enable sub components of .NET 3.5: WCF HTTP and Non-HTTP Activation. (Did you know that you can do such things here?)
    image
  4. As I have installed IIS after installing Visual Studio 2008, I had to register the ASP.NET components for IIS by executing C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe –i
  5. Finally you have to register WCF as well for IIS (to understand the .svc extension for example). You can do it by executing C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe –i

If you have followed these steps (plus maybe a few more restart) you will be able to host WCF services on IIS 7.

Visual Studio 2008 can help you to configure and debug the virtual directory for you, but for this feature you have to run Visual Studio as administrator.

image

But fortunately there is an informative error message if you forget to do so.

image

Windows 7 and developing WCF applications

by Gáspár on January 15, 2009

Yes, I know that this is weird, but I have installed Windows 7 to my development notebook to see how it survives. (Ok, I have a backup XP as well on the machine.)

Generally it works very well, I have not found any major problem with Windows 7, and it seems that the stability has been improved a lot since the pre-beta.

The only problem I have encountered so far is with WCF service applications. If I create a WCF service and host it on the ASP.NET Development server, then all of the WCF requests return an HTTP error:

The remote server returned an unexpected response: (400) Bad Request.

WCF Test Client error dialog

This can even be reproduced with the simplest WCF service that is created for example with the “WCF Service Application” project template.

It is also interesting that the service serves the WSDL request well, it just produces the error when you call a service method. With IIS (after I was able to set it up) the service worked fine.

I have no idea currently what can cause this behavior, but it can be reproduced on other Windows 7 machines as well.

Update: It’s a known security-related issue with Cassini in Windows 7 beta build 7000 and will be fixed in next release. (see http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/123f0d20-a018-48b0-ab92-4aae749f2d5e/)

Thanks to Johan for the update (http://weblogs.asp.net/jdanforth/archive/2009/03/14/bad-request-with-wcf-service-in-cassini-on-windows-7-beta.aspx).