Jun
11
2010

From WPF functional Unit Tests to Specifications using MSpec and White

I am in the train back home and wanted to try out quickly to migrate our WPF functional tests written has Unit Tests to BDD Specifications.

Here is the code I started from, pure Unit Test using NUnit and White

[Test]
public void Opening_Valid_VersionZip()
{
    OpenAndWait("Product.zip");

    Assert.That(MainWindow.Title.Equals("Product.zip - Innoveo Skye® Editor"));
    Assert.That(Status.Text.Equals("product"));
    Assert.That(ProductTree.Nodes.Count >= 1);
    Assert.IsFalse(SplashScreen.Visible);
    Assert.IsTrue(SaveButton.Enabled);
    Assert.IsTrue(ActivateButton.Enabled);
}

Now the same functional test written as a BDD specification using MSpec

[Subject("OpenVersionZip")]
public class when_user_open_valid_versionzip : MainWindowViewSpecs
{
    Establish context = () => {};

    Because of = () => OpenAndWait("Product.zip");

    It should_display_mainwindow_title_correctly = () =>
        MainWindow.Title.ShouldEqual("Product.zip - Innoveo Skye® Editor");

    It should_display_status_correctly = () =>
        Status.Text.ShouldEqual("product");

    It should_display_the_product_tree = () =>
        ProductTree.Nodes.ShouldNotBeNull();

    It should_hide_the_splashscreen = () =>
        SplashScreen.Visible.ShouldBeFalse();

    It should_enable_save_button = () =>
        SaveButton.Enabled.ShouldBeTrue();

    It should_enable_activate_button = () =>
        ActivateButton.Enabled.ShouldBeTrue();
}

And the output in ReSharper MSpec plugin

4687909611_49a4e5a71a_o[1]

Which one do you prefer? I personally have made my choice.

Jun
4
2010

Build .NET projects from Windows Explorer using MSBuild Launch Pad (mPad)

In September 2009 I posted about a tool I am using to build my MSBuild projects from the shell “Build your .NET project with a right click in Windows Explorer

Last week I changed to MSBuild Launch Pad (mPad) which also add a context menu when you right click your project or solution files.

The added value for me is that it maintained project, 1.0 was released on May 21, 2010 with following release notes:

    • Support sln, csproj, vbproj, vcxproj, shfbproj, ccproj, oxygene and proj files execution.
    • Basic settings such as Show Prompt, and Auto Hide are provided.
    • MSBuild Shell Extension integration is achieved.

I also very much like that when I right click and say build I get the control on the .NET framework version I want to use and if it is a Release, Debug or what so ever.

4668737460_d5f6fd3791_o[1]

Nice little productivity booster tool.

Jun
3
2010

Build and Deployment automation, VCS Root and Labeling in TeamCity

As you might now from reading my blog I tend to automate as much as I can.

Why? Because I hate to do repetitive tasks. First because it is boring, at least for me, and as a developer we have more interesting things to do. Second because executing repetitive tasks tend to be error prone.

So last week I decided that it was enough for me to have to create manually a subversion tag for Jobpingweb site then also took the time to do the same for my portal Tech Head Brothers.

At Jobping we are using TeamCity and Subversion. We use it as our Continuous Integration system but also to deploy to production server in one click. Something I promised to talk later on in more details.

So it was relatively easy to configure TeamCity so that after build/deployment process it tags our subversion.

First of all, I realized only the other day the way TeamCity works with VCS root 

A VCS Root is a set of settings that defines how TeamCity communicates with a version control (SCM) system to monitor for changes and to get sources for a build.

We are using the convention of trunk, branches, tags in our Subversion server (which is the great Visual SVN Server). In the past I always set the TeamCity VCS Root to our myproject/trunk url, and I have seen lots of people doing so on different websites/blogs…

At this point I realized that I missed a point with TeamCity VCS Root is that it contains Root in it’s name. So I might be using myproject/ in place of myproject/trunk as the VCS Root. But wait, if I do that TeamCity agent will make a checkout of my whole Subversion repository!

And here comes the VCS Checkout rules, which you can configure on every project which is using the VCS Root

4663096481_231787d2d1_o[1]

So in my case it looks like that

4663731014_a4945d38d0_o[1]

Which specify that for that particular build I want to checkout from my VCS Root extended with trunk to the build folder /. So with that I restrict the checkout to the trunk. Good

Now back to my first topic, which was to automate the subversion tag creation when our build is successful which is done using TeamCity VCS Labeling.

Here is how we set it up for our staging build

4663125553_c725cbc3dc_o[1]

For sure we have another one for our production build.

And here is the result in Subversion

4663756592_592d22d287_o[1]

Another thing that I will not forget as it is automated

One last issue that I had which you see only if you register to get info about failed build in TeamCity is the following

[TeamCity, LABELING FAILED] Staging - CI Trunk, Unit Tests, Deploy #1072

Jetbrains.buildServer.vcs.VcsException:

Labeling the path 'trunk' to 'tags/staging-1072' has failed with the error: svn: MKACTIVITY of '/svn/!svn/act/7caf50f8-2801-0010-9e80-1fedd46c5a33': 403 Forbidden

With this error message it was then easy to figure it out. I just had to modify the access right of the build user to have read/write access right and not only read.

Jun
1
2010

Using Gmail as TeamCity smtp server

Some time ago when I had to reinstall our Jobping Continuous Integration server, which is Team City I also decided not to reinstall any smtp server but to use Gmail server.

Here is the configuration that I used, which worked perfectly for me

4656773327_09a7eed279_o[1]

Use SMTP port 465 and TLS (SSL) !

May
22
2010

Missing a little FileAccess.Read and it doesn’t work

What is the difference between this code

using (var fileStream = new FileStream(settingsFilename,
                                       FileMode.Open))
{
    return ReadSettings(fileStream);
}

And this code

using (var fileStream = new FileStream(settingsFilename,
                                       FileMode.Open,
                                       FileAccess.Read))
{
    return ReadSettings(fileStream);
}

Almost nothing, just a little FileAccess.Read !

But this little thing makes a big difference when you run your software in a secured environment.

The application with this piece of code was deployed to a customer reporting that the application was crashing at a the point of reading the settings. Weird, really weird. After getting back the log and I finally discovered that using juste FileMode.Open needs modify rights and that’s was the issue because the customer deploy the settings file on a folder in which the user doesn’t have the modify rights.

May
21
2010

f.lux Better lighting…for your computer

A couple of month ago I was introduced by a colleague to f.lux.

At first I thought, hum ok another software that will just eat some memory for nothing. But after 2 days, in fact 2 evening, yeah I work a lot in front of monitors, I was conquered and I recommend this tool to all like me that spend their days and nights in front of monitors!

From f.lux pages

Ever notice how people texting at night have that eerie blue glow?

Or wake up ready to write down the Next Great Idea, and get blinded by your computer screen?

During the day, computer screens look good—they're designed to look like the sun. But, at 9PM, 10PM, or 3AM, you probably shouldn't be looking at the sun.

F.lux fixes this: it makes the color of your computer's display adapt to the time of day, warm at night and like sunlight during the day.

It's even possible that you're staying up too late because of your computer. You could use f.lux because it makes you sleep better, or you could just use it just because it makes your computer look better.

f.lux makes your computer screen look like the room you're in, all the time. When the sun sets, it makes your computer look like your indoor lights. In the morning, it makes things look like sunlight again.

Tell f.lux what kind of lighting you have, and where you live. Then forget about it. F.lux will do the rest, automatically.

flux-shot[1]

May
19
2010

ASP.NET MVC 2, MSpec and Watin

The other day I posted about “Automated functional tests using Watin and MSpec” which we do at Jobping as a spike to automate our functional tests on our ASP.NET MVC 2 site.

Yesterday evening I was facing an issue in my base class WebBaseSpec which led to really strange side effects. Basically when I was running one unit test alone it was Green, running all or more than one unit test will fail miserably with the well known STA issue of Watin.

So I thought that I had an issue with the ReSharper MSpec plugin but after some discussion with Alexander GroßI realized that the second failing test was showing another issue than the STA issue.

Going further I realized that when I was checking the following

It should_direct_user_to_aboutus_page = () =>
    Browser.Uri.Route().ShouldMapTo<HomeController>(x => x.About());

First I needed to call the ASP.NET MVC RegisterRoutes

MvcApplication.RegisterRoutes(RouteTable.Routes);

which was done in the constructor of my WebBaseSpec class.

protected WebBaseSpec()
{
    MvcApplication.RegisterRoutes(RouteTable.Routes);
    InitBrowser();
}

That’s was the problem, I was registering the routes several time, one time per test. So first one was ok, second one was failing…

So I modified it to the following, ensuring that the routes were registered only one time!

private static bool registered;

/// <summary>
/// Initializes a new instance of the <see cref="WebBaseSpec"/> class.
/// </summary>
protected WebBaseSpec()
{
    if (!registered)
    {
        MvcApplication.RegisterRoutes(RouteTable.Routes);
        registered = true;
    }
    InitBrowser();
}

Now I can run all my functional tests again

4621024158_d2c99039a0_o[1]

May
14
2010

Jobping Open Source URL Shortener. Goes to Version 0.5

We have updated our url shortener for Jobping. jobp.in has moved along to Version 0.5. While maintaining as little features as possible!

Since the initial version we have placed a restriction(web.configurable) on the domain names that the shortener will shorten. We did this so only domains under jobping.com would be processed by the shortener. We wanted to maintain the integrity of the jobp.in domain. With this in place you can be sure that if you click a link shortened by http://jobp.in  it will always go to our site www.jobping.com site.

This version also includes a new custom style, which looks awesome and is now slick and styled inline with our main site Jobping.

4603509097_c8c3439491_o[1]

The new version can be downloaded from codeplex here: http://jpurlshortener.codeplex.com/

May
13
2010

Automated functional tests using Watin and MSpec

I am conducting a spike for a couple of evening on the way we might automate our functional tests at Jobping

I started with Watin and MSpec and the MSpec excellent plugin for ReSharper 5 which gives the following great outputs directly from Visual Studio

 4602612162_a3a0e50945_o[1]

After some discussion with Alexander Groß (Thanks for your help ;) to gain some knowhow about MSpec I finally managed to have some automated functional tests running like this:

[Subject("Search")]
public class when_user_search_using_keywords : WebBaseSpec
{
    const string Keywords = "C#";
    static SearchScreenObject searchScreenObject;
    static ResultScreenObject resultScreenObject;

    Establish context = () =>
        {
            searchScreenObject = new SearchScreenObject(Browser);
            resultScreenObject = new ResultScreenObject(Browser);
        };

    Because of = () => searchScreenObject.Search(Keywords);

    It should_direct_user_to_results_page = () =>
        Browser.Uri.Route().ShouldMapTo<HomeController>(x =>
            x.Search("AU", new SearchRequest { Keywords = Keywords}));

    It should_fill_search_textbox_with_keywords_entered_by_user = () =>
        resultScreenObject.SearchText.Text.ShouldEqual(Keywords);
}

I think it talks for itself!

Remarks to note:

  1. SearchScreenObject and ResultScreenObject represents an isolation layer between my tests and objects that are present on the web pages. This helps in the case you decide to change an id of an element
  2. I use MvcContrib ShouldMap to ensure that the browser navigates to the correct destination page which add another isolation layer and let me change my URL without impacting my tests

It is really funny to see the browser opening and clicking automatically, typing texts…

Hopefully, at the end this will replace our smoke test document and quite some time of manual testing.

May
12
2010

Fundamental Laws from David S. Platt on MSDN Magazine

Yesterday I got the new issue of MSDN Magazine in my mailbox and as often I started to go quickly around it to get an overview of what kind of subject’s it talks about. And as often I end up at the last page’s article which is the first I am reading.

This time David S. Platt is writing about “Fundamental Laws” which start like that

Whenever I find a program or Web site that sucks, it’s invariably because the developer or designer forgot the user’s goals and started embellishing the program for its own sake.

This reminded me a discussion I had a year and a half ago at Christmas time when my brother was back from Australia. We were discussing about what became Jobping.

And as you can read fom Jobping  press release, “Jobping launches niche job website listing Microsoft skilled vacancies”, it is one of our priority:

More features and functions based on user feedback and requirements will be implemented quickly as Jobping takes an organic and user oriented approach to product development.

From David

Your software has zero value in and of itself. Nothing. Nada. Zero point zero zero. The only value it ever has or ever will have is the degree to which it enhances the happiness of your user in some way

So when you develop software you’d better understand and listen to the problem of your users to delight them and enhance their happiness.

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect, certified Scrum Master and Founding Member.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent was awarded Most Valuable Professional (MVP) by Microsoft from April 2002 to April 2012.

JetBrains Academy Member
Certified ScrumMaster
My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List