Automatic testing for dummies

Automatic testing is no substitute for all tasks around testing. However, for some parts of the test cycle, it is very useful. But, where to start? In this blog, I will give you a practical introduction. My basis is the way that I work, so please consider this a quick start, and see how you can fit this into your own way of working. By the way, all tools and tutorials mentioned in this blog are available for free, also for commercial projects!

 

Test object

It is much easier to write tests for a practical situation than for something hypothetical. So, my first tip, find a test object so you can practice with automatic testing. However, do not start without the permission of the object owner. When you start with automatic testing, you can add some strain to the test object, servers, etc., and not everyone is keen on accepting these effects. It is therefore sometimes wiser to select a website or application that is managed by you or your company. But even then, get some approval. 

 If there is no test object available within your domain, or is your time for setting this up limited, just see if you have something lying about. Something you worked on in the past? Something you have developed yourself or a blog site? Use that as your practice environment. 

 As an example for this article, I have chosen a website that has been developed with Laravel (PHP) and MySQL. 

 

Choices

It is especially important to start by asking yourself what you want to test and to what category it belongs. For instance, do you want to execute functional tests and examine whether a website loads correctly and fills the webforms accurately? Or do you want to do a smoke test, performing different checks to see if the website works at all? I have chosen a functional test because that is where I can gain the most time and efficiency in my testing.

I want to test my website by visiting pages and checking whether certain elements are shown. Furthermore, I want to click on links, fill forms with data, and send them. To find a suitable tool I will start with Google. I will look for test tooling for the website, considering the type of test I want to perform. The best way is to search on development criteria like technology or language (in this case  ‘Laravel’, ‘PHP’, ‘Website’, ‘MySQL’) and words like ‘Automated Testing’ of ‘Test tooling’. This sounds obvious, but this gives you a quick overview of everything that is available. The information you will find in general falls into three categories: vendor websites (the developers of the tools), tutorials and user questions and known issues. First, read the documentation of the vendor. That will give you a clear understanding of what a tool can do, what it is aimed at and how you can apply it in your test approach. 

Do not forget to check out the tutorials. Usually, you can determine how complex and challenging the tooling is and what other features it offers you. The questions and the known issues can come in handy later.

Test setup 

First, a little side-step. With automatic testing you will need test tools. These tools usually work fine for their purpose. But if you want more (more different tests, check of results, better reporting, auto start, et cetera) you can broaden your setup. What you usually see in these cases, is the use of a framework that integrates all your test tooling. You setup your tests within that framework. Examples of these kind of frameworks are JUnit en TestNG. They are usually focused on unit testing, but are also very well suited for functional tests. A framework offers all kinds of opportunities for integration (both process and tooling) and the use of external data (data driven testing), parameters, logging, reporting et cetera. You can also combine tools (like Selenium for functional testing and Rest Assured for testing webservices in one test run). Furthermore, there is tooling for reporting, like Allure. Something to consider because the reports produced by frameworks usually are not that attractive. But always keep your focus and stick to your needs. And then, if you think certain parts can improve, go and look for an approach or tooling to improve. 

 

Do not do this on your own 

If you are working on test automation and you are part of a project team, it is a good and smart idea to involve the developers. There is a good chance that the automated tests ‒ now or later ‒ will have an impact on their tasks and responsibilities. Automatic tests can benefit from the integration with the development project and usage of the same version control system. It is always good to team up with the developers. Let’s face it, writing code is their thing; why would you assume you can do it better than the pro’s!? And the developers can help you make better choices on tooling and setup, based on the characteristic of the project, their experiences and estimations on needed knowledge, time, and effort. 

 

Tool selection 

Time to start executing the functional test on the website. A popular tool for that goal is Selenium. It executes all kinds of actions for you within the browser, like clicking on links and entering data in a form. You can use Selenium in two ways. You can record, change, and execute with the plugin (Selenium IDE, available on Chrome and Firefox) or write your test yourself with code (Selenium WebDriver). Because of the scalability and flexibility, I prefer Selenium WebDriver. Also, I select TestNG as a framework, because that offers me more options for controlling, planning, and executing tests. With TestNG, I can also use a startup and teardown script; default actions that will always be executed before and after each test case. 

 

Let’s get started! 

There are a lot of online tutorials to help me set up both TestNG and Selenium in a project. We need an IDE (Integrated Development Environment), a tool we can use to write code. We could use Notepad of course, but an IDE helps you to structure and to setup. An IDE also provides you with all kinds of useful suggestions. And perhaps you have noticed: Selenium also has an IDE available that allows you to record and execute Selenium tests but also has the option to write tests. My choice however is Selenium WebDriver and a separate IDE because that offers me the flexibility to integrate another tooling. Eclipse is the IDE that is used the most and which is available in all environments. (Side note: Visual Studio is growing in this area because of its broad functionality and integration in other domains. But has a license model!) We set up our test project in Eclipse and write our test in it. We could even execute the tests through Eclipse. 

 

Develop your tests 

I got my website and my setup, so know it is time to start writing my tests. And luckily, here too there are all kinds of tutorials available. The most important rule here: use as much Ctrl+C and Ctrl+V as possible. Find (test)code that seems to do what you need, copy and paste and see how it works! Start small, see if you can make it open a browser and load the website. Work from there, expand your test until you have a complete test script. Of course, it is important to have test cases before you start, because you need to know what you are going to automate before you start developing. 

 

Automating existing tests 

Usually, you start automating your tests within a project that has been running for some time and for software that has been written. A couple of times I was given the assignment to automate all the tests. For an existing solution that no small deal. Where to start? My advice: start with testing new features. For those features, you immediately start with automated tests that can be included in the regression set. Next, you could start automating the existing regression tests. Keep in mind, and explain to the (product) manager, a fully automated test set cannot be developed in a week. However, with good planning, it also won’t take years. 

 

I hope you have a good first impression of how and where to start with automatic testing. The most important advice that I can give you is: just do it! Don’t be afraid of writing code, just try it, you will probably like it! And although ‘real’ testing will always be needed, automatic testing can relieve you of a lot of repetitive, time consuming (and sometimes boring) tasks. 

 

To sum up 

All my tips summed up: 

  • Find a project 
  • Find a tool (sometimes a few for your specific needs and setup) 
  • Find a friend (a developer, a peer, tutorials) 
  • Find a starting (new features than slowly but surely move into automating regression tests) 
  • Find information (Google, StackOverflow, experienced colleagues) 

 

One last bonus tip: check ToolsQA, for a lot of great tutorials on automated test tooling, like Selenium in JAVA. 

 

Enjoy and good luck! 

Our latest articles

Want Craft updates sent straight to your inbox?

By clicking send you'll receive occasional emails from Craft. You always have the choice to unsubscribe within every email you receive.

Mail

Newsletter

Want CRAFT updates sent straight to your inbox?