Gherkin Tips & Tricks

A few months ago, I was selected to give a presentation at the Testnet ‘voorjaarsevenement’. My talk was about Gherkin and how to improve your Feature files and step definitions.  It’s time to put it on the blog.

Instead of writing an introduction to Gherkin, it’s better to point you to the Cucumber wiki. They have a very good explanation of it. So let’s move on to the tips & tricks!

Feature file tips

  • Avoid long descriptions
    Features should have a short and sensible title and description. This improves readability and you do want readable and understandable Feature files, don’t you? So there should be one sentence describing the scope and content.
  • Choose a single fomat
    I don’t care if you pick “As a [role], I want [feature] so that [benefit]”  or “In order to [benefit], as a [role] I want [feature]”. However, pick one and stick with it. Again, this improves the readability. And never forget the benefit, this makes it easier to decide on the business value.
  • Features… not big portions of the application
    There should only be one Feature per file and the Feature should be reflected in the file name. If you work in larger teams, it is easier to work parallel on smaller Feature files.
  • Domain language
    Involve the customers and use their domain language. Involve them in writing the user stories or at least have them review them. Keep the language consistent accross all Features (and even projects).
  • Organization
    Organize your Features and Scenarios with the same discipline like you would organize code. You can organize them according to execution time: fast (<1/10s), slow (<1s) or glacial (>1s).  Or put them in separate subdirectories. Or tag them.

Background tips

  • Use Backgrounds
    To avoid repetitions in the feature file, Backgrounds are ideal. However, since the user has to keep the Background in mind while reading or writing the Scenarios, keep them short. Max. 4 lines.
  • Don’t include technical stuff
    The Feature file is about the user. Starting or stopping the webserver, clearing tables, etc can be implemented in the Step Definitions. it shouldn’t be mentioned in the background.
    Of course, don’t use a Background if you have only one Scenario.
  • Don’t mix
    Don’t mix backgrounds in the Feature file with @before hooks in the Step Definitions. This will drive you nuts when debugging.

Scenario tips

  • Scenario vs Scenario Outline
    In fact it is very simple: if you have only one example, use a Scenario.
    If you have more than one example, use a Scenario Outline and a table
  • Short
    Keep your scenarios short.
    Hide the implementation details.
  • Declarative steps over imperative steps
    Using declarative steps is much more concise and about WHAT the user wants to do with the system, not HOW the user wants to do it.
    Declarative example:
    Given I have logged on to the system
    Then I should see my new messages
    Imperative example:
    Give I am on the login page
    When I fill in the username
    And I fill in the password
    And I click on the ‘Submit’ button
    Then I should be logged on to the system
    And I should see my new messages

Step tips

  • AND/OR are keywords
    so don’t use them within a step
    Given I’m on the homepage and logged on
    Should be
    Given I’m on the homepage
    And I’m logged on
  • Cover happy and non-happy paths
    Testing is more than only proving it works. It’s trying to break the system.
  • Refactor
    Your library of steps will increase in time, so try to generalize your steps to increase reuse.
    You understanding of the domain will increase also, so update your language and the steps.

Tag Tips

  • Never tag the background
    Tags allow you to organize your Features and Scenarios. You can have multiple Tags per Feature or Scenario, so never tag the Background.
  • Don’t tag Scenario with same Tag as Feature
    Feature Tags are also valid for all child Scenarios, so there is no need to apply the same Tag to the Scenarios.
  • What is the benefit of Tagging a Feature
    You can Tag individual Scenarios, so think about what value would be added by Tagging an entire Feature.  There may not be much use for it. Except perhaps Tagging the Feature with the story number.
  • Tag categories
    Possible tag categories may be
    Frequency of execution: @checkin, @hourly, @daily, @nightly
    Dependencies: @local, @database, @fixtures, @proxy
    Level: @acceptance, @smoke, @sanity
    Environment: @integration, @test, @stage, @live
    Some groups also Tag according to progress: @wip, @todo, @implemented, @blocked.
    I’m not saying this is bad, if you do, make sure you keep the tags up-to-date! If you can’t do that, don’t use them.

Step Definition Tips

Most of the tips below will increase the reuse of your Step Definitions and the readability of the Feature files.

  • Use flexible pluralization
    Add a ? after the pluralized word:
    Then /^the users? should receive an email$/ do
    Now it will match both user and users
  • Use non-capturing groups
    Instead of (some text), use (?:some text). Now the result is not captures and not passed as an argument to your step definition.
    It is especially useful in combination with alternation:
    When /^(?I|they) create a profile%/
    or
    And /^once the files? (?:have|has) finished processing*/ do
  • Consolidate Step definitions
    When /^the file is (not)? present$/ do |negate|
        negate ? check_if_file_is_not_present : check_if_file_is_present
    end
  • Use unanchored regular expressions
    Normally you anchor start with ^ and end with $. Sometimes it might be useful to omit one:
    Then /^wait (\d+) seconds/ do |seconds|
        sleep(seconds.to_i)
    end
    This will allow for more flexible expressive steps:
    Then wait 2 seconds for the calculation to finish
    Then wait 5 seconds while the document is converted
    Of course this can be dangerous, so I think you can only do this for this example 😉
  • Be DRY
    Don’t Repeat Yourself.
    Refactor when necessary and reuse Step Definitions within a project across Features and perhaps even across projects.
  • Parse date/time in a natural way
    For most programming languages there are libraries that allow you to parse dates and times in a more natural way. For example in Ruby you have Chronic and in Python you can use parsedatetime or pyparsing.

So there we have it: quite a few tips to improve your Gherkin Feature files, Backgrounds and Step Definitions.

However, most important tip I can give you is to exercise discipline when writing your test automation code:

  • treat your code as production code
  • refactor when necessary
  • run your tests as often as possible
  • and don’t be too smart: somebody needs to understand next year. And that person might even be you.

For your benefit I have included my presentation and the checklists I created.

Decoding mp3 files with a right click

Recently I made a very good deal on a used NI Maschine Mk1.

maschine-mk1-2

It is a nifty musical device, includes lots of drum kits and allows me to quickly make some nice tracks (or better: musical snippets).  It’s lots of fun!

Another part of Maschine is that it really simplifies sampling, like this guy demonstrates:

Lots of people take old vinyl records and record a sample through a Numark record player.  I don’t have a Numark and I don’t have vinyl records. But I do have lots of CD’s ripped to mp3 files. Unfortunately Maschine doesn’t support mp3 files, only wav files.

How to convert them?

  • Of course there is Audacity and it even allows batch conversion, but it still is a too much work: open Audacity, open files, batch convert, close Audacity, …
  • I’ve tried looking for programs that would allow me to right click the file in Windows Explorer and convert it. They are available, often install add/malware, but no free programs or they are way to heavy.

Solution: Lame. Next to encoding files, it can also decode them with the –decode option.

Adding that command to the context menu can be done with NirSoft FileTypesMan. (check out the other tools at NirSoft!) Open FileTypesMan, search for mp3, Add new action ‘DecodeToWAV’. For the command-line, browse to the directory where you put lame.exe and add ‘ –decode’. That’s it!

Right click samples in Explorer, select DecodeToWAV and moments later you have a .wav version in the same directory. Couldn’t be simpler.

Sharing your limited hotel wifi network

Sometimes you stay at a hotel and they provide you with a free or paid Wifi connection. However, it is limited to only one device. And there you stand with your phone (data is too expensive since you are roaming), tablet (perhaps only Wifi available) and laptop…

No worry, open source to the rescue!

Step 1: Buy a DD-WRT compatible router.

For example a TP-Link TL-WR841N for something like 20 euros. If you already have a router, but you are not sure if it is DD-WRT compatible, look it up in their database.

Step 2: Install DD-WRT

Find the correct download files.  For the TP Link you can find them at their site.
Next steps are:
-Make a cabled connection between your laptop/pc and the router. Disable wireless on your laptop.
– Plug in the router and turn it on
– Get a new IP address on your laptop. Open a command prompt on your laptop and enter:
ipconfig /release
ipconfig /renew
– Point your webbrowser to http://192.168.0.1
– Go to system tools – firmware upgrade. Select factory-to-ddwrt.bin and upgrade. When done, reboot the router.
– Get a new IP address on your laptop. Open a command prompt on your laptop and enter:
ipconfig /release
ipconfig /renew

– Now point your webbrowser to http://192.168.1.1 (note the change)
– Set a new password
– Navigate to administration, firmware upgrade. Log in again if needed. Click browse. Select tl-wr841nd-webflash.bin. Click upgrade and reboot when done.
Congratulations, your router is now running DD-WRT!

Step 3: Configure your DD-WRT router to share the Wifi connection

The goal is to have the router log on to the hotel network with the settings they gave you and create a virtual interface to create a new wireless network for your devices.

Based on the default configuration, change following settings:

Wireless tab, Wireless Physical Interface:
Wireless mode:client, save
Wireless Network Name: [SSID of the hotel network], save

Wireless tab, Virtual Interfaces: (you may need to add a virtual interface)
Wireless Mode: AP
Wireless Network Name: MyNetwork
Wireless SSID Broadcast: enable, save

Wireless tab, Wireless security:
Physical Interface [SSID of the hotel Wifi]: [password of the hotel network] and save
Virtual Interfaces [MyNetwork]: WPA2 personal, AES
WPA Shared Key: [enter here the password you want for MyNetwork], save

Setup tab, Basic Setup:
WAN Connection Type: Automatic – DHCP, save

Network Address Server Settings: DHCP Server:
DHCP Server: enable, save
DNSMasq for DHCP, DNSMasq for DNS, DHCP-Authoritative: all yes, save
NTP client enable, UTC+1 (for ttraff daemon), save

Setup tab, Advanced routing:
Operating Mode: gateway, save

Services tab:
DNSMasq: enable
Local DNS: disable
NO DNS rebind: enable
ttraff daemon: enable, save

Security tab:
disable all checkmarks, save
SPI firewall: disable, save

Administration tab:
Reboot Router

Since the MyNetwork wireless network will only be available when the router can connect to the hotel network, you have to bring a network cable to connect your laptop to the router.  If you change hotel, connect the laptop with the cable (refresh the IP) and change the SSID and password of the ath0 interface. Your settings for MyNetwork can stay the same.

It might also happen that you need to fill in a name and a password on a webpage. Once when my laptop was connected via the router, the forwarding to that login page didn’t work. Connect your laptop directly to the hotel Wifi network and see to which page it is forwarded. DO NOT FILL IN THE PASSWORD, but copy the URL.
Now connect your laptop back to the router MyNetwork and paste the URL for the login page and log in.  All devices should now be able to use the hotel network.

Studying for Professional Scrum Master exam

Agile and certifications, is this a good match?  Usually agile supporters are proud to not be certified.

I don’t know, but at least several founders of Scrum seem to think it is. You have 2 big Scrum certification organisations:

  • Scrum Alliance, who have the Certified Scrum certifications (Master, Product Owner, Developer, Professional, Coach and Trainer).
    ScrumAlliancePath
  • Scrum.org, who have the Professional Scrum certifications (Masters, Developers and Product Owners). Scrum.org has 2 levels for almost each type, so there is a Professional Scrum Master I and II. (PSM I, PSM II). Likewise there is a PSPO I and II.  Only Professional Scrum Developer only has one level at the moment: PSD I.

What is the difference between the 2 organisations?  Well, I’m not involved in either of them, so I only know what I found out on the internet.  Time for some gossip: Scrum Alliance started first around 2002, but by 2009 Ken Schwaber had become extreme dissatisfied in it: the organisation he helped create was more interested in and dependant on the money coming in than in the mission.  So he founded Scrum.org. A longer description of this history is available (albeit a bit hidden) on the Scrum.org website.

The certifications of the Scrum Alliance do seem to go further. Especially the Scrum Coach and Trainer are not easy.  It is not just taking an exam, but demonstrate over 1500 hours of Scrum coaching with real client references.  So if you see a Certified Scrum Coach, you know that the customers were indeed satisfied with the word delivered. These certifications however are beyond my experience at the moment, so let’s focus on the Certified Scrum Master and Professional Scrum Master.

What is the difference between these certificates? Well, again, I only took the Professional Scrum Master assessment, so I know absolutely nothing about the Certified Scrum Master certificate.  However, I do know that it is possible to take the PSM assessment without having to follow a training, while this isn’t the case for the CSM. So that was one of my reasons for taking PSM I.  That both Ken Schwaber and Jeff Sutherland are involved in Scrum.org seems to be another plus.

So, how to prepare for the assessment?

  • First step is to read the Scrum Guide. Don’t let the number of pages, 16,  fool you.  There is really a lot in it. But it is the basis for the assessment.  Everything that is assessed, is in this document! Although I must say I got a few extra questions on burndown charts for example. So do not only read it, but study it carefully. You should not only know that something is done or not, but also why, understand Scrum!
    Even though I had followed the Certified Agile Tester training (and give it also), I still found new things in it.
  • Learn more about Scrum best practices not described in the Scrum Guide. Not necessary for the assessment, but it helps to better understand why certain choices were made.
  • Try to gather some experience. More difficult since not every project is an Agile project, not every Agile project is a Scrum project and many ‘Scrum’ projects are ScrumBut projects. A ScrumBut project is of course not a good preparation for the assessment.
  • Take the Scrum Open Assessment.  These are only 30 questions (the assessment is 80 questions),  but there is a larger pool, so if you take it several times, you get a few more questions. Before you take the real assessment, you should get consistently at least 29 on the Open Assessment with time to spare. For extra insight it is useful to  take the Developer Open Assessment also several times. You need a Scrum.org account to be able to take the Open Assessments.
    I noticed several questions from the Open Assessment coming back in the real assessment.
  • Follow the suggested readings list for Scrum Master on Scrum.org. There are many good books available.  All of these can give you extra insights.

Then the assessment itself, is it difficult?

Not so much, I scored 95%. If you know Scrum and understand it, achieving the required 85% should be quite easy to do. I needed 25 minutes to go through all 80 questions. So that left me plenty of time to go back to the bookmarked questions.  Some needed indeed some adjustment, but in the end I could finish easily in time.

So, does this prove I am now a good Scrum Master?

Of course not, no multiple choice exam can prove that. Just like ISTQB Foundation doesn’t prove that you are a good tester.  It only proves that you know the terminology, some techniques, have an understanding of risks, etc.  Prove that you are a good tester? That can only be done on the job.

Likewise, this certificate does prove that I know Scrum. And perhaps also that I can apply it. Doing this on a real project, with real people/organizational/time issues and constraints, that’s the next challenge!

Test data generation tools

As a tester you’ll often need to generate test data.  A lot can be achieved with Microsoft Excel or Open/LibreOffice Calc or any other spreadsheet. However there are tools specialized in generating test data.

Several commercial tools focus at generating big data, like those of Grid-Tools, Tricentis and probably several others. Since I haven’t used these, I’m not going to discuss them.

There are also several smaller, free tools that you can use!

  • GenerateData: open source data generator with lots of possible fields, even country specific ones. Very useful.
  • Fake Name Generator:generates a single identify for online use.  Especially useful for online social networks. Disadvantage is that it can’t generate a whole CVS files with hundreds or thousands of records.
  • Mockaroo: seems simple, but it also allows regular expressions, so almost everything is possible.
  • Credit card numbers: has a list of fake credit card numbers conform to the MOD10 algorithm.
  • Identity generator: allows to generate various types of files with fake data, specific data fields for UK, US, Canada and the Netherlands are available.
  • TextMechanic: not so much test data generation, as a set of tools to manipulate text online.
  • Random: list of free and paid online tools to generate data, but also pick random data (times, dates, passwords, geographical data, …)
  • TypeIt: if you need to test internationalization of your application. Generates/displays all characters in lots of character sets.
  • BabelCode: slideshow of all possible unicode characters.  Needs more than 3 hours to display each character it knows!

In my opinion these are indispensable tools for any serious tester.  Add them to your bookmarks and start using them.

My list of tools for Windows

I’ll admit it: most of my work is still done on a Windows box.  Linux is used on my home server and of course at most of the clients Linux is used in the embedded systems or as server OS for the applications. But my laptops all use at least Windows, next to Linux in some cases.

So here is my list of free or open source tools that I immediately install on all of my machines:

  • Dropbox: Why Dropbox and not Drive, OneDrive, Box, SugarSync, Wuala, …? Well, because I used a Google AdWords campain to max out my Dropbox at 19GB. So this is quite convenient.
  • Winsplit Revolution: I know Windows has application window management since Windows 7, however, in my opinion Winsplit Revolution is much easier to use and faster with the possibility of the key combinations.
  • Launchy: Again, with the Windows key a lot of the same functionality can be achieved.  However, I let Launchy also index my Dropbox folder with the portable apps, so that at each new pc I always have all my tools under my fingertips.
  • 7-zip: no need for any other (de)compression tools.
  • IrfanView: fastest image viewer and lightweight editor that can handle almost any image type, especially with the extra Plugins/Addons.
  • Paint.NET: already overkill for my graphical needs, but still easy to use and fast startup.
  • Sysinternals Suite: there is always a useful tool in this suite, be it at least Autoruns.exe.
  • ConEmu: best command prompt replacement. Althoug I should take a look at Cmdr.  It wraps up ConEmu and Clink in a nice package.
  • Putty: for your shell needs to Linux machines.
  • Clink: to enhance your command prompt to the command line editing features of Bash.  So small, so very useful!
  • Notepad++: immediately replace notepad.exe with this editor.  There are very useful plugins available.
  • Keepass: I sure hope you are not using the same password for all websites and applications?  Keepass helps you keep track of these passwords.  I know Lastpass and other web applications provide the same functionality.  However, that makes them also the prime targets for hackers, so I’ll just keep track of them myself.
  • FreeFileSync: so useful to easy sync files and folders between computers.  A tool like this is absolutely necessary to allow backs.  You do make backups, don’t you?
  • VLC: forget about MediaPlayer, just install VLC and be done with it.

I also want to point you to Scott Hanselman’s list of tools for Windows.