(repost) Using HTTP mocks when developing and testing

When developing applications the following can also happen to you. External service not being available, external services not completely finished (yet), external services not having a test environment, no ability to test unhappy flows (like functional error or more technical errors)

So, you might want to test your application in isolation with limited dependencies on external services.

This is where mockhub.io comes in. Mockhub.io allows you to create HTTP response messages using an intuitive form. No programming experience is required when using Mockhub. Mockhub.io works with sophisticated matching criteria to decide what kind of response it should return. Any HTTP response can be set in order to simulate faulty responses. Mocks and their logs can be suspended to allow faster performance.

Share This:

The tool is not the challenge…

but the process can be… Nowadays there are several modern and robust test automation tools out there, which can automate nearly anything. So, that should not be the real problem anymore. The problem lays in the process and how people approach test automation. I have seen people automating very big end2end flows, which result in a lot of maintenance work. Also, a common habit is to automate everything through the User Interface, which results in very long test cycles.

When doing test automation it’s very important to find the right balance between the types of tests. If you don’t find the right balance, you will definitely end up with high maintenance costs and very long test cycles.

Some projects have a limited budget and are therefore very focused on the output teams can deliver. How teams deliver becomes, for the decision makers, less important. Strange isn’t it? Because this way of thinking doesn’t contribute to the long-term goals of your product.

Imagine the situation where you can deliver fast, but code quality is poor and test coverage is even worse. After some time the costs will rise enormously, I’m talking about the costs for maintaining and testing the system.

So, the underlying message of this brief blog post is that technically everything is possible but think twice if you put the delivery of new feature above the delivery of high-quality software. In no time you will create technical debt, which is more expensive in the long run.

Share This:

Romanian Testing Conference 2017

This year I was invited to do a workshop of my own choice. It turned out to be an “Improve your Selenium WebDriver Testing” workshop. So, I went the 10th of May to Romania to join the conference. The first expression of Romanian people is that they are really friendly, open and honest and luckily their English is also really good. Anyway, those were very good ingredients to start an interactive workshop.

My workshop

There were 32 attendees for this workshop. It was a little bit overwhelming (in a positive way) because normally I put a limit of max. 15. Surprising for me was that half them were women. (That didn’t happen so far at workshops I gave in the past in mainly The Netherlands.) It went pretty good. I started with a theoretical overview of why and what you should automate. After that, we went to the specifics of Selenium WebDriver. All participants enjoyed the locator game, which is available here: http://locator-game.selenium-in-action.io/ . After the lunch, we started to iteratively fix tests and implementing the Page Object Model to achieve better maintainable tests.

 

On my second day of the conference, I was delighted to join the presentations of the day. So, herewith a brief summary of the presentations I attended.

Passion wanted to leave me, but I convinced it to stay, by Santhosh Tuppad (Twitter: @santhoshst)

A presentation presented with a lot of passion. He started his career with a few one-week jobs before he found his passion as a software tester. He said: ‘You need to find your passion because the passion doesn’t find you’. I think he is very right with this statement.

Testing the energetic consumption of software: why and how, by Paulo Matos (Twitter: )

Poorly developed applications consume more energy and they can drain your batteries. (from your phone/ iPad / smart watch). Energy might be cheap in the Western world, but it isn’t in, for example, Africa or remote areas. Also, the batteries of mobile devices are very limited. So, it might be good to optimize your application in regards to the energy consumption, especially when developing mobile applications. CPU/GPU cycles are the most expensive. After all, he demonstrated some tooling you could use to visualize the energy consumption per application.

Succeeding as an introvert, by Elizabeth Zagroba (Twitter: @ezagroba ‏)

A nice presentation about how to survive in a project/organization as an introvert person. Surrounding people should be aware how to react to introvert people. (they won’t keep asking things to identify all possible risks up front) Funny thing was that I actually recognized a lot of the things she said.

Debugging your test team, by Keith Klain (Twitter: @KeithKlain )

One of the points he made was to fire all test managers who spend more than 25% on non-testing activities. Like the typical spreadsheet managers 🙂

 

Test automation – the bitter truth, by Viktor Slavchev (Twitter: @Mr_Slavchev)

He nailed the points on why automating everything is impossible or inefficient, really spot on. He also pointed out that we need to change the definitions, in order to set the correct expectations. “Programmatic testing” in stead of “test automation”. (so, managers don’t expect a huge cost saving and traditional testers don’t expect that their testing will be automated.

Independent tester – A game changer, by Uros Stanisic (Twitter: )

Organizations are requesting more and more T-shaped testers. He described what value a tester can add other than ‘just’ testing.

12 vs. 18, who says “we” cannot be “them”? , by Harry Girlea

This was an amazing talk from a 12-year-old boy standing in front of about 500 people. He pointed out that children start early with playing games, nevertheless, they are never part of testing (because they are legally too young). A solution he presented that they (kids) can be paid with game points.

 

All in all an awesome conference! Very eager to attend next year as well.

 

Share This:

Tips to make your (web) application testable

This blog post will provide you some tips to make your (web) applications better testable. This is an initial list of tips and can be extended of course. The idea is that you can use this list when you have discussions with your developers about testability.

  1. Unique identifiers
    Especially when doing UI testing, it’s important to have unique identifiers on the page. There are different approaches: assign an `id` to every element or assign a unique identifier to each component and input element.Implementing id’s for every element is costly and unnecessary.Implementing unique identifiers for every component is a better approach because they can search relatively within that component. Like, you have a search component with an input field and button:

    <section id="search">
     <input type="text" name="query">
     <button type="submit" name="search">Buscar</button>
    <section>
    

    Now you can construct the following CSS locators:
    section#search
    input[name='query']
    button[name='search']

    Although it’s not needed, I’m in favor of defining the type of the element.

    When not having these unique identifiers you will probably end up with very hard to maintain locators. A few examples:

    .//*[@id='wx-header-wrap']/div/div/div/div[2]/div[2]/div/section/div/form/input

    or

    .//*[@id='gnav-header-inner']/div/ul/li[2]/a

    The first is too long and therefor unreadable. The latter is much shorter but is tightly coupled to the second list-item (li[2])

  2. Separate environment
    Once, I was on a project where the test-database was shared with multiple test environments. I believe this was done to save some costs, as we depend on a huge Ora cle database. Cost-saving is fine, but it had some drawbacks.

    • Different testers/teams are manipulating the same data;
    • Different versions of software are processing the same data;
    • Different message-consumers are messing with the data.

    This was not very convenient and after some debate we found the budget to duplicate the environment (including database and all services). The result was an isolated environment for running our automated tests.

  3. Mock third-party services
    When testing in general, depending on data which is outside of your control and become a nightmare. Because of the following:

    • Third-party service can decide to switch-off the servers;
    • Third-party service can decide to clean the (test) database, so the data is not present anymore;
    • Third-party dataset is very limited.

    You might decide to stub/mock the third-party services if you recognize one/some of the above. When stubbing/mocking third-party services you have full control over the data and you can even easily simulate error-responses/timeouts/etc.

It would be great to hear your tip, so I can add them to the list. Feel free to leave a reply (tip + argument and in what situation did you benefit from it).

Share This:

Clean(er) Test Automation Code

This blog post tries to explain why it is important to really care about your test (automation) code and write clean (automation) code. I’m mainly involved in test automation, so some of the examples given are related to that, but most are related to programming in general. Often test automation code is less exposed to a formal review process. Keep in mind; test automation is code and should threated like that.

I hope this blog post will bring you one step closer to clean(er) code.

Test Class Naming
Defining a classname for unit testing is rather easy; it’s the same name as the implementation class. In terms of functional or integration testing, the classname should reflect the feature or functionality you are testing.

For example:

public class LoginTest { }

public class RegistrationTest { }

public class OrderTest { }

Test Method Naming
I have been on many projects, some Greenfield* others continuing development on an existing codebase. Every project has its own naming convention* or not ☺. The following can happen in projects without naming convention:

@Test
public void test1() { }

@Test
public void test2() { }

// or:

@Test
public void testLogin() { }

Do you get the point? It’s all very descriptive, isn’t it?

Imagine you have to share this with a colleague or you have to present the results to non-tech colleagues, they have no clue what’s going on.

I very much like the naming convention introduced by Roy Osherove (http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html). The basic idea to describe the tested method, expected input or state and the expected behavior as the name of the test method.

public void nonExistingCredentialsGiven_ShouldThrowException() {

}

We can adopt this principle for feature testing as well.

public void nonExistingCredentialsGiven_ShouldShowErrorMessage() {

}

By following this naming convention we can make sure that the intent of the test is clear to everyone. (Off course the implementation should reflect the method name) Method names are a bit longer, but self-explanatory.

Naming of fields and local variables

Another thing that strikes me is the use of non-explicit fields or variable name. Like:

i for loops
page when applying the Page Object Model (everything is a page lol)
And so on..

We need to be more explicit if we want to create readable code.

Magic numbers
Magic numbers indicate the direct use of a number in your code. By doing this, your code becomes less readable and harder to maintain.

Example implementing magic numbers:

public class Username {

	private String setUsername;

	public void setUsername(final String username) {
		if (username.length() > 10) {
			throw new IllegalArgumentException("username");
		}
		this.setUsername = username;
	}

}

After refactoring

public class Username {

	private static final int MAX_USERNAME_SIZE = 10;
	private String setUsername;

	public void setUsername(final String username) {
		if (username.length() > MAX_USERNAME_SIZE) {
			throw new IllegalArgumentException("username");
		}
		this.setUsername = username;
	}

}

The refactored example allows you to easily update the maximum size of a username, even if it’s used in different methods.

A general rule of thumb might be when applying any naming convention is to be very explicit.

Greenfield: setup a project from scratch.
Naming convention: set of rules

Other Test Naming Conventions: https://dzone.com/articles/7-popular-unit-test-naming

Share This:

Genereer Leanpub book

While writing a book (Leanpub) it might be useful to quickly replace a lot of variables in one go. Therefore I created this tool. GenerateBook-all-1.0.jar

The tool expects to following directory structure:

|-orig/ (folder containing the original files)
|-manuscript/ (if this folder does not exist it will be created)
|prop.properties (file containing all variables you want to replace)

Example prop.properties file content:
authors=Author1 and Author2
demo.url=http://example.com
software.version=12.3

Usage:
To use this tool: java -jar GenerateBook-all-1.0.jar

Example output:
Copied: orig/chapter1.md to manuscript/chapter1.md

I hope this tool is useful for you and additional features can be requested via comments.

Share This:

Use Sonar to Check the Quality of Test Automation Code

sonarsource-300x94I am working now for more than one year on a test automation project with thousands of lines of code. I started this project on my own, but during the year much more people got involved. Everyone with their own coding-style. We needed to guarantee the quality of the code written by those people. Therefore we introduced Sonar which performs static code analysis and can find violations of standards. The analysis includes:

  • Coding standards;
  • Code duplication;
  • Code complexity;
  • Potential bugs;
  • Code comments;
  • Unit Test coverage;
  • And more…

Writing test automation code is like doing “normal” development. So you have to apply coding standards, patterns to avoid duplication and reduce complexity, code comments to describe what each function does. Sometimes when testing safety critical systems you have to write unit tests for the test automation code as well.

Sonar gives you insight in all those areas. It became very clear to me that some test automation developers have bad or uncommon practices. (See screenshot of the dashboard)

dashboard-300x138

Sonar gives the ability to fix or resolve those bad habits.

Installing Sonar is fairly easy

Analyzing your project is even easier and can be done in three ways:

  • Sonar Runner
  • Ant Task
  • Maven Goal

That said, I think the first week of this year was very effective, we have taken the automation code to a higher level.

Share This:

2013 Retrospective: a year’s reflection

Just a couple of day and the year 2013 comes to its end. It’s time to look back and reflect what I have done this year. Quite a lot of things came across my path: daily work, sales meeting, testing conferences, writing articles, training people and my promotion. Yes, you read it well, I have been promoted to a different business unit: consultancy 🙂 ! (this means that I will do a bigger variety of assignments across the Netherlands) I worked for the following customers in 2013:

SpilGames Implementation of an automated testing framework using the open source stack.

Dimpact Implementation of performance testscripts to measure the server-side performance (Jmeter) as well as the client-side performance(WebDriver).

Steinweg Tool selection for a new testautomation implementation for their entire landscape. (ongoing)

Sanoma Implementation of performance testscripts to measure the server-side performance (Jmeter) as well as the client-side performance(WebDriver). (ongoing)

Hema Test Automation POC using C# / WebDriver.

Postcode loterij Test Automation implementation using Java / WebDriver.

Richard Oosterhof PHP Selenium Automation. (ongoing)

Below a list of articles I wrote in 2013:

May 2013: “Implementeren van Behaviour Driven Development” in the Spring Special of TestNet Nieuws (TestNet Nieuws 2013 – 1, page 14)

June 2013: “Behave yourself – BDD for testers” in Professional Tester (Issue 21)

June 2013: “The benefits of BDD” in Professional Tester (Volume 5: Issue 3)

September 2013: “Implement Maintainable Test Scripts by applying Design Patterns” in Software Developer”s Journal (Selenium 2 WebDriver)

Below a list of conferences I visited in 2013:

May 2013: “Het overbruggen van de communicatiekloof met Behavior Driven Development/Testing (BDD/T)” at the Spring event of TestNet (Event)

June 2013: “Structured functional automated web service testing” at Test Automation Day in Rotterdam (Event | slides)

July 2013: “Aan de slag met Selenium WebDriver” at TestNet Summerschool (Event | slides – “Aan de slag met Selenium”)

November 2013: “Getting started with Selenium WebDriver” at Software QS Tag in Nürnberg (Event)

Share This:

Test Automation Day NL 2013

Herewith a very short update. I was very glad to be part of Test Automation Day 2013 with my track on “Structured Functional Automated Web Service Testing”. I was even more pleased to be introduced by Dorothy Graham.

Please find the slides of my presentation below:


I really liked the final keynote by Emily Bache (@emilybache) with her vision on “The Future of Test Automation”. This was a very inspiring talk! She spotted two trends in our industry. The first one has to do with Lean Startup, a method for developing successful products. The second trend is towards distributed architecture, independently deployable components communicating via messages. Below you will find a quick summary photo of the keynote.

EmilyBache

I’m looking forward to the next Test Automation Day edition!

Share This:

Plans for 2013

It’s time to set some goals for the coming year, 2013.

2013-150x150

Changing work schedule
Last year we noticed that there are coming a lot of requests in the area of test automation. Therefore, my employer and myself have decided to change my work schedule. From now on, I will work 4 days at the same client and I will have 1 flexible day (which I can spend with other clients). Personally I like this change very much, because I get the ability to work in other environments as well.

Special Development Program (SDP)
A selective group of Polteq employees are selected for SDP. I’m one of them… 🙂 This consists of a curriculum of a wide scale of trainings, both soft skills and hard skills. We will spend 65 evenings together (till March 2014) to learn a lot of new things to become a better consultant. It”s a great opportunity to learn so many things in such a short period of time.

Blog
I aim for a weekly or biweekly post in 2013. Those posts will cover my experiences and things I learned on the job and in the Special Development Program. This also gives me the ability to look back and reflect what I have done and learned.

Selenium/WebDriver trainings
Also in 2013 I will work as a trainer to spread my knowledge about Selenium/WebDriver and test automation in general. I hope we will gain a lot of new Selenium/WebDriver enthusiastics. Probably I will also be involved in development of other technical courses.

Articles and conferences
Furthermore, I like to attend some conferences (like: Testnet.org, EuroStar) and write some articles to well-known magazines/websites (like: TestingExperience and SoftwareTestingClub.com).

Personal changes
But the best thing for the coming year is that we are going to have our first child 🙂 That means that I will work half days for 4 weeks, so I can spend some quality time with my wife and the baby.

Share This: