Friday, 14 January 2011

Acceptance Tests, Fluent Interfaces and a DSL

Lately ive been doing quite a lot of acceptance testing. We did give some BDD frameworks a try especially SpecFlow, but were left with a feeling that it was too complex for the benifits that it gave, was too inflexable and in the long run could turn into a bit of a mess. well that was the evaluation of the team, im sure there are good ways of doing it that is valuble but we decided not to go with a framework.

So i came up with a DSL that gives the developer a simple 'Given When Then' syntax that im quite pleased with, it allows for the most readable / maintainable acceptance test ive seen to date.

A small acceptance test follows as an example:

using NUnit.Framework;
using OpenQA.Selenium;
using AcceptanceTests.Domain;

namespace AcceptanceTests.Fixtures
{
    [TestFixture]
    public class TagTests : BaseTestFixture
    {
        [Test]
        public void ThisAndThatShouldDoSomeThings()
        {
            var resultsPage = Page.SiteABC.ResultsPage;
            given.WeAreOnThePage(resultsPage);

            when.I.Click.TheElement(By.LinkText("civil-engineering"));

            then.TheUrlShouldBe(Page.SiteABC.Article("civil-engineering"))
                .And.TheTitleShouldBe("civil-engineering articles in ABC example page");
            then.TheElement(By.ClassName("tag-wrapper")).ContainsTheText("Articles with the Tag:\r\ncivil engineering");

            when.I.Type("london").Into(By.Id("txtLocation"))
                .And.I.Click.TheElement(By.LinkText("search"));

            then ..... (You get the idea)
        }
    }
}

The base class gives the test fixtures access to the Given When Then classes similar to this:

public class BaseTestFixture
{
    protected Given given;
    protected When when;
    protected Then then;

    [TestFixtureSetUp]
    public void SetUp()
    {
        given = new Given();
        when = new When();
        then = new Then();
    }
}

The actual Given When Then classes delegate the actions to webdriver in the following manner:


public class Given
{
    private readonly WebDriver webDriver;

    public Given()
    {
        webDriver = WebDriver.GetCurrent();
    }

    public Given And
    {
        get { return this; }
    }

    public Given WeAreOnThePage(Page page)
    {
        webDriver.Driver.Navigate().GoToUrl(page.Url);
        return this;
    }
}


public class When
{
    private readonly WebDriver webDriver;

    public When()
    {
        this.webDriver = WebDriver.GetCurrent();
    }

    public When And
    {
        get { return this; }
    }

    public When I
    {
        get {return this; }
    }

    public IAction Click
    {
        get { return new Click(this); }
    }

    public TypeText Type(string text)
    {
        return new TypeText(text);
    }
}


By writing the step classes like this we can write the tests in a fluent style, making for very readable. This is important as it enables none technical (business) people to read / understand the tests and have input on the creation of the tests, although i admit it still does not really enable them to write them, as you do need to know c# and visual studio, but in my experience they never write them anyway (especially on the contact im on), its technical people who write the automated acceptance tests.

All in all im quite pleased who the suite of tests is progressing and how the DSL has evolved.

Thursday, 6 January 2011

LauncherPro has expired. 403 forbidden. Phone is locked out...

Ive been using LauncherPro for a couple of months now, its a nice homescreen replacement on the android phone, actually i really liked it.

But this morning when i turned my phone on i got the error :-

"This version of LauncherPro has expired. Please goto http://www.launcherpro.com/ to get the latest version."

Then my web browser automatically opened so i could get it but i had a problem, i had no internet connection, no wifi, and no mobile connection.... arg.. Basically my phone was now a brick, well i could receive calls, but there was no way to access anything else as every time i hit the home key it would redirect to the internet...

Then later on in the morning i went into london and got a connection on 3G but then i got a 403 forbidden page.... double arg, whats going on this is so shoddy, so i still cant use my phone.

Only after getting to a PC with a decent internet connection did i managed to find a couple of solutions, the first was to download an app installer onto the pc and do a remote install of the new version of launcherPro, i didnt like this, it sounded too complex and i wanted rid of it not the latest version.

Then i found the following solution
browse to - http://bubiloop.com/download/org.adw.launcher
this should open the market (app store)
then search for launcherPro and finally update or uninstall.

I recommend un-installing, seams like this is a rather shoddy product if it locks out your phone like this. even if the actual software does everything else well i dont think this sort of error is in any way acceptabe in any software ever, locking you out of your device, laptop, PC whatever it is, is just wrong, i appreciate the developers might want to force people to upgrade all the time, but this is just not on, i dont know i just cant warn you folks enough, i woudnt trust this app.

morel of the story, dont use apps from random developers on major bits of your device, the home screen is quite major, if that dont work your stuffed.

Monday, 13 December 2010

Edward Deming and his Red Bead Experiment, in practice.

We had an interesting brown bag lunch meeting the other day about Edward Demings red bead experiment. I've heard and read about it before but never got to participate, it was interesting, thought provoking and fun. Some good discussions afterwards as well.

Edward Deming was a management consultant and statistician. He had a massive impact on the management styles and philosophy of Japanese business in the 50's and 60's. He used the red bead experiment to illustrate the impact that a system, and traditional management approaches, can have on individuals who work within a system, and how traditional management approaches (slogans, the usefulness of targets, annual appraisals and financial rewards) are not always (if ever) that effective at improving quality.

Details on the red bead experiment and how it is performed can be found here http://www.redbead.com/. For our results in the actual experiment read on.

Results
The session was run by a thoughtworks colleague, in a really good way, we had the workers, the management, the QA staff, and lots of fun.

The workers were set targets of 5 defects max per person ( a total of 15 per iteration for the team)
The 3 workers, were split into 2 average and 1 good (what ever that means)

Iteration1234Developer Totals
Dev1685726
Dev21075729
Dev378101136
Iteration Totals2323202591

After iteration 1 workers were told that their efforts were not good enough, and basically told off by management. This made no difference, and so, after iteration 2 the workers were given incentives and appraisals, if they upped their game they would be given hard cash. This worked and management were encouraged to do more of that, offering bigger rewards for better performance.
But iteration 4 was the worst yet and so managers assumed that the incentives had failed because no one actually achieved them last time.

So what does this actually tell us?
That in a fixed system where the workers have no ability to manage or better themselves or their work, the management effectively can not effect workers performance though traditional carrot and stick management.

How does this relate to Software?
I have found that as software developers we don't get to change the system as a whole very often. Often software is seen as the solution to business problems, when actually changing the system would be a better approach. Just by making the process electronic doesn't always work and often makes things worse or masks the underlying problem. This is just another reason why software projects fail.

The experiment also relates to the software development process. If software engineers work in a rigid system where QA and strict process is seen as putting the quality in. Where the engineers don't have the ability to change their environment (technology, process, physical environment, methodology) then no amount of incentives, slogans, rewards can make the software produced better (less defects, meeting business requirements more effectively, etc.). I have seen this at several clients, and can say that clients who have empowered workers have a big advantage, these companies have better motivated, more professional developers and in the end better software.

Summary
Systems Thinking is a really interesting field at the moment and if you want to read more do a google for Edward Deming, systems thinking and John Sedden.

So even if you are CMM level 5 (i.e your processes are robust and repeatable) you can still have quality issues, The red bead experiment highlights that it is not process that produces quality, nor rewards, targets or incentives, its the system within which workers work that matters and their ability and motivation to help change and adapt the system.

Tuesday, 7 December 2010

Selenium 2, webdriver for .net c#

Webdriver tests that are fast to write and fast to run are essential for BDD. I was really supprised at how fast your tests can actually run, even the setup is quick IE opens instantly, providing a very quick test code loop.

1. Download selenium 2 from http://code.google.com/p/selenium/downloads/list i got selenium-dotnet-2.0a6.zip for this exmple
2. Add project references to nunit.framework, webdriver.common and webdriver.IE or webdriver.firefox
3. Using NUnit (No tutorial for that here, google it) create a test class that uses webdriver


using System;
using NUnit.Framework;
using OpenQA.Selenium.IE;

namespace AcceptanceTests
{
    [TestFixture]
    public class Class1
    {
        private InternetExplorerDriver _driver;

        [TestFixtureSetUp]
        public void FixtureSetUp()
        {
            _driver = new InternetExplorerDriver();
            _driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
        }

        [TestFixtureTearDown]
        public void FixtureTearDown()
        {
            if (_driver != null) _driver.Close();
        }

        [Test]
        public void GoogleShouldBeInTheTitleWhenNavigatingToGoogleHomePage()
        {
            //Given
            _driver.Navigate().GoToUrl("http://google.co.uk");

            //When

            //Then
            Assert.AreEqual("Google", _driver.Title);
        }
    }
}

4. Run your tests
5. Done

Wednesday, 3 November 2010

Android, how easy is it to deploy or install your own app to your phone

The answer is very easy

So you have spent a few hours developing a new android app (ive been using the eclipse IDE) and you have been testing using the adb emulator, but you want to see something on your very own android hardware (ive got a HTC Desire).

These are the steps ive followed:
  1. Build your .apk package.
  2. Connect your phone to your pc in disk drive mode (this enables you to mount it on your pc).
  3. Browse to your removable disk (this shows up as drive G: on my machine).
  4. Copy the .apk file that was generated by the build to your phone and remember where you copied it to.
  5. Disconnect the phone.
  6. On the phone use a file manager app like 'ES File Explorer' or 'ASTRO File Manager' and browse to the .apk file you copied on in step 4.
  7. Open the .apk file and select install.
It really is that easy, none of that iphone certificate nonsense, or limited use to tolerate, lets just do it :-)

Setting the date on Android emulator adb

To set the date on your android emulator use the following command from the terminal

adb shell date -s 20101023.130155

This sets the date to be Oct 23rd 13:01:55 2010
easy

Friday, 29 October 2010

20 things that are wrong with TFS, and counting

We have recently spent a lot of time using TFS 2008, im no expert with this tool but it seems to me that there are lots of issues with it. Its not that im trying to do some TFS bashing but my last project using subversion didn't have source control problems.

As always though if anyone out there can put me right on any of these issues please do so.

  1. Renames and deletes don't always properly get merged between trunk and branch and back.
  2. We had really random deletion of files when doing a merge from a branch that has had a baseless merge applied to it, (files were randomly deleted off the trunk during merge) these files existed in our branch and the trunk before the merge, but were removed off the trunk after.
  3. After doing a baseless merge (using power tools on the cmd prompt) you then can't reliably use the TFS GUI to do things like merges, you must use the command line tools.
  4. Tooling just doesn't work when merging, files that have no conflicts just don't auto merge all the time and requires manual intervention for no reason. This is intolerable when refactoring and you have changed 100+ files.
  5. No ability to create patch files which can be subsequently applied to other branches.
  6. Changes to one branch cant be merged into another branch unless you go via the trunk.
  7. You cant merge workitems between branch and trunk, even though workitems are the main unit of work in TFS.
  8. Many standard features like rollback are not built in. It requires an additional 'power tools' download (There is no GUI for rollback)
  9. Can't seem to rollback to a given point in time, you can only rollback 1 changeset at a time, this just seems wrong to us?
  10. Using TFS built in diff tool reports lines that have no changes to have changes. And does not line up source and target very well making the tool very hard to use when trying to spot important differences.
  11. Doesn't know that files or folders have been added unless you tell TFS in the GUI, This can easily lead to files not getting checked in if they were not created in visual studio.
  12. The GUI doesn't always update to reflect the state of the source control, requires a refresh, this mainly effects the pending changes view.
  13. The UI is confusing in that if you are browsing the source and click on a file to open it, it opens the local copy not the one in source control. Also it doesn't tell you that the local is different from the one in source control.
  14. When you add a new mapping to your workspace the tool says 'do you want to update your workspace?' when you say yes it then goes and gets everything from your workspace and updates everything, you expect it to only get the changes due to the new mapping. this caused us quite a lot of confusion and wasted time, but luckily nothing was lost.
  15. Sometimes labels disappear, completely, as if they were never created.
  16. A label to label comparison does not always give the same results as a date to date comparison, even though the dates used are the same as when the labels were created.
  17. Checking out (not getting) the entire branch takes ages (40 minutes plus) even though the source is not really that big (70,500 files), we actually gave up in the end and 1/2 were checked out 1/2 were not.
  18. Deleting a branch took 40 minutes. Did a delete in TFS of the branch folder (took 10 mins) got a pending delete dialogue box, tried to check in the delete which failed with the error 'the local copy is not up to date', so we then undid the delete which took 20 mins, got the latest source (3 mins) and finally did the delete again (10 mins). Why cant TFS tell us up front the delete wont work because our file system is not up to date? and why when doing it in the TFS GUI does our local file system matter? especially since we had no pending changes?
  19. When you re-branch you lose your branch history.
  20. If you tolerate this, then your code will be next...

Tuesday, 28 September 2010

C# .net method call performance

I’ve recently been in a conversation with another dev about a code base and had an alarming exchange regarding method calls and performance.

Alarming because he claimed that the reason that the methods in the system were so long was because someone higher in the dev chain 'tech lead' or 'architect' had claimed that it was expensive to make method calls???

I’ve seen my fair share of long methods, awful things that destroy reuse, developer productivity, and introduce many, many tangled bugs. These usually evolve because the devs are under pressure to get things out of the door on tight schedules, or by inexperienced devs who unfortunately don’t know much better. Personally I like to try and keep my methods short <20 lines, to keep to the principal that a method should only do one thing, do it clearly and well (so its easy to read, understand and change), you know all the usual stuff. But I’ve never seen the justification for long methods to be because of performance...

so i thought what is this performance gain of long methods? After googling around I didn’t find anything (if you do let me know) so i wrote a program.

Essentially it consisted of 2 loops, one to do a simple calculation in line and one to call a method to do the same calculation.

for (int i = 0; i < LoopCount; i++ )
{
fakeCalculationVariable++;
}


for (int i = 0; i < LoopCount; i++ )
{
Calculate();
}

i took timings before and after each loop and recorded the results

LoopCount= 100000000
elapsed time = 234.447 milliseconds
elapsed time = 640.8218 milliseconds
Method call loop took 406.3748 millisecs longer than inline loop for 100000000 calls
Thats a cost of 0.0000041 millisecs per method call

i wasn’t sure about the results so i decided to run it again, this time with ten billion iterations of the loop, these performance penalties must show up with that many calls.

LoopCount= 1000000000
elapsed time = 2250.6912 milliseconds
elapsed time = 6376.9584 milliseconds
Method call loop took 4126.2672 millisecs longer than inline loop for 1000000000 calls
Thats a cost of 0.0000041 millisecs per method call

its quite conclusive, method calls don’t really add up to all that much overhead, as we all expected.

Sunday, 12 September 2010

Azure Learnings

A few months ago I played with Azure, experimented with all the storage options (table, queue, blobs) web and worker roles, made things interact and generally got to know what was possible, not possible and how to do things. It was interesting, i gave a few presentations to the company I was contracted to at the time but in the end it was all just exploration, they were never going to take it up (they own lots of their own hardware, i mean Lots, and besides in my view there are issues with going to Azure as a solution for that enterprise problem), also I didn't see any use for it in my own personal projects.

I had a MSDN account which at the time entitled me to 750 compute hours a month (a compute hour is just a measure of how long your roles have been deployed in the cloud), and was careful with my deployments, always take test deployments down to minimise the total compute hours.

Anyway two problems:

1st. I didnt check my subscription(why would i?) it turned out i had the basic "starter" subscription (50 free compute hours) not the MSDN package (750 free hours).

2nd. I did a demo and someone wanted to use it afterwards so i left it up (one web role and one worker role) and then forgot about it... opps. To add to my woes my hotmail account is not my primary email account so the billing was not coming to me, i only just found it when I happened to be on hotmail.

To cut a long story short I got charged £50 + £120 + £120 for the honour of having my dummy website sat doing nothing on the azure application fabric... I;ve since talked to Microsoft and cancelled my azure account, i see no need for it, I'm not going to use it any time soon, and wanted to make double sure all my web instances were gone. but after talking to them i have got last months money back, better than nothing but still... i guess it was my fault for not checking my package, my running instances and my email, stupid boy.

Morale of the story to all you perspective Azure developers out there, check your subscriptions, and always take down your test deployments, always.

Wednesday, 1 September 2010

Site creation with google sites

Just been through the process of setting up a new website http://sites.google.com/site/stangerphotography/ new picasa site and new flickr account http://www.flickr.com/photos/oliverstanger/ for my brother who is setting up a photography business.

It was actually quite easy to do once you get used to navigating your way around the site and the wysiwyg editors. Managed to fully set up google analytics and web master tools also.

Now I just need to make sure my brother updates his content.