Skip to main content

Good principles of test automation

Core principles of good tests
When you start automating your tests, there a few important principles to stick to.

Reliable
First your tests must be reliable. This means that they must repeatable and always give the same results. They should not contain any environment dependencies, and be executable on any environment. To get this working, all hard-coded settings must be configurable, a maven or ant script is required to build and configure the test environment, and all code, test date and configuration scripts must be checked in source code repository. Having reliable tests that run everywhere and always, also means that your tests must take care to setup necessary test data, and clean it afterward again.


Fast
Next, it would be nice when your tests are fast. In the lifetime of a project you will build up ever more tests; with every next sprint you will need to run more tests. You can't run all your tests on check-in, and for certain groups of tests need to schedule test execution times at less regular intervals.

Self explaining tests
Also your tests should be easy to understand, and have clean reports. Easy to understand means that an outsider can quickly understand what the test is about. Proper naming helps a lot here, additionally you can add document tags to the comments. It also helps to stick to the domain language so that it is easy to map test cases to use cases.



Clean reports
Test reports should have a clean baseline. Try to avoid including known bugs, as they clog up the test results, and make the news bugs less visible. Also in your asserts add meaningful log statements that help finding the root cause of the failure.

Continous integration
Further you want your tests be integrated in continous integration build process. You will probably want to create several groups and have some of these more frequently executed than others. Once you have them running automatically, you are sure that they actually get executed, and you also make sure that they are really reproducible. Before you add your tests to CI you must make sure though that your test reports have a clean baseline. Else people will ignore the test reports.


Continuous integration of test environment setup
Deployment and execution of tests in CI environments is the easy part. Far more difficult it may be to set up and configure your test environment. This includes setting up your application server, initialising your database, starting your application server, deploying your application and configuration of appl server and application. This will require a lot of specialist knowledge.
One step further you may also want to mock your connection proxies to external connections. This may be for instance a credit card provider. You don't want to send your payments that you generate in tests to a real provider. So you will need to mock the provider's functionality and have your test environment set up with this mock interface instead of the real one.

Testability
A last point of attention concerns testability. Some of your application's functionality may be difficult to test as you can't reach it with your testing code. Examples could be a status of an object that you have just changed, and can only be checked by a UI application. As a tester you would like to have direct access to this functionality, so that you can use it for the asserts of the test. These testability functionalities are additional requests to the developers. They will need to build it in the code, just for the sake of testing. Other important testability examples are: fixed IDs for html elements, or some deleteFunctionality to clean up test generated objects.

Comments

Popular posts from this blog

Create a groovy console and bind to selenium

Required groovy files In the previous posting we defined the pom file that we need for our build environment. Now we will setup some groovy files to get selenium and groovy running interactively. ConsoleWaiter.groovy The idea of Groovy Console I found on some other sides. Honour goes for instance too: http://josefbetancourt.wordpress.com/tag/eclipse-2/ I copied some code of this, and put it under src/test/groovy/com/jankester/selenium/test/utils: package com.jankester.selenium.test.utils /** * File: ConsoleWaiter.groovy */ import groovy.lang.Binding; import groovy.ui.Console; /** * Provides a wrapper for the console. * * Based on source by John Green * Adapted from: http://www.oehive.org/files/ConsoleWaiter.groovy * Released under the Eclipse Public License * http://www.eclipse.org/legal/epl-v10.html * * I added methods to allow use from Java. * * The run() method launches the console and causes this thread * to sleep until the console's window is closed.

SSL handshake failed: Secure connection truncated

Got this problem on Ubuntu 9.10 and 10.10. svn co --username=xx https:/yy zz “SSL handshake failed: Secure connection truncated” According to this link bug-ubuntu The solution is: sudo apt-get install libneon27 cd /usr/lib/ sudo rm libneon-gnutls.so.27 sudo ln -s /usr/lib/libneon.so.27 libneon-gnutls.so.27

Junit4 running parallel junit classes

To run junit testcases parallel, you can create your own class to run junit with: Add this tag to your class declaration. @RunWith(Parallelized.class) Implementation of this class looks like: package mypackage; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.junit.runners.Parameterized; import org.junit.runners.model.RunnerScheduler; public class Parallelized extends Parameterized {         private static class ThreadPoolScheduler implements RunnerScheduler     {         private ExecutorService executor;                 public ThreadPoolScheduler()         {             String threads = System.getProperty("junit.parallel.threads", "16");             int numThreads = Integer.parseInt(threads);             executor = Executors.newFixedThreadPool(numThreads);         }                 public void finished()         {             executor.shutdown();             try