This post is part of the same presentation given by myself and Bruno Souza at the JavaOne Conference 2017 in San Francisco.
Although extremely important, we are not talking here about unit testing and integration testing, assuming you already know what it is and already apply it, as a developer concerned about the quality of your code.
Test Automation Pyramid and Agile Testing Quadrants
Creating tests is the easiest and quickest way to test your application and ensure that if any bug appears, you will find it before your client.
Currently, we cannot talk about testing without talking about test automation. The application of the test automation gives a quick feedback to the team and maintains the execution of the regression tests continuously.
The approach we can use to take a greater speed in automating, executing and having a rapid feedback of the tests is the application of the Test Pyramid, which is a guide for the application of automation in at least three levels: unit, services and ui (user interface).
The services layer is being divided into three parts: component tests, integration tests and API tests.
The unit testing layer is the most important layer of our application because we will create tests for the code that we are developing and guarantee its work as expected, even after future maintenance (recommending the use of TDD — Test Driven Development). In this layer, we can apply code coverage analysis and static analysis practices in order to intensify the rapid feedback against a defect that may appear.
The service layer (component, integration and API) is extremely important nowadays, with a large focus on API testing. Here we apply mocks, stubs and fakes to give speed in the execution of microservice tests. We also need separate test environment servers, where this can be the closest to a production environment.
The UI (User Interface) layer is also important, especially from a mobile testing perspective where, when a customer encounters an error in an app, it usually removes it. The most important techniques here are automated testing in UI and Visual Regression Testing. In the web part, we need browsers to execute the same test in different ones (IE, Chrome, Firefox, Safari). We need the same for mobile automation testing: iOS and Android devices to ensure the compatibility of our app on these two platforms.
The Agile Testing Quadrant, created by Brian Marick and widely disseminated by Lisa Crispin and Janet Gregory in his book “Agile Testing — A Practical Guide for Testers and Agile Teams” are some practices that can be applied during the activity-focused development of the test. The quadrant is a guide: it is not necessary to perform all the existing practices in it, you can choose one or more depending on your context.
Continuous Delivery and Testing Pipeline
There is no way to talk about DevOps without talking about Continuous Delivery (CD) … without it, we could not even talk about the DevOps culture.
In Continuous Delivery, one of the foundations is the Continuous Testing where we must test all the stages of our development (pipeline) with an initial recommendation applied to unit tests and automated acceptance.
Continuous Delivery enables joint roles between Development, QA and Operation. An example of evidence-focused collaboration for these roles is:
- Development + QA: Build, Deploy and Test automation at various levels
- QA + Operations: Test Automation and Continuous Feedback through test executions, as well as sanity test executions
- Operations + Development: Automated provisioning of machines/ containers required for testing at any level.
Now we continue with the pipeline focused on tests, which can be applied in whole or in parts, being:
Unit Test and Integration Test
We can create mocks/fakes/stubs to remove the dependencies and acellerate the test executions
ServiceTest: on service layers (SOAP, REST)
- Smoke: small execution subset to guarantee that all API’s are working (at least return status different from HTTP 404 or HTTP 500)
- Contract: a collection of agreements (tests) between a client (consumer) and an API
- Functional: tests that want to guarantee the operation against different business rules (happy path, sad path and alternative flows)
- Acceptance: evaluate the system’s compliance with the business requirements and assess whether it is acceptable for delivery
Acceptance: acceptance testing
Tests that focus on the user perspective and knowing as end-to-end testing (e2e). Important to simulate the user journey on the application.
- Smoke: main test suite what will guarantee your business running
Functional: functional testing
Tests that guarantee the operation against different business rules (happy path, sad/negative path and alternative flows)
- Smoke: main test suites of a happy path, sad path and alternative flows
From Integration to Functional Testing (end of the pipeline) we have to worry about non-functional tests. Examples of tests are functional: performance, load, security, etc …
And it’s extremely necessary to create an entire automated test architecture to support the continuous, automated, and least-maintenance run possible with:
- screenshots to evidence the execution of each test, or evidence when an error occurs
- logs to analyse and see any error occurred
- reports to show up a feedback about the test execution
- data management for the sensitive data on a test script
- parameterize commonly changed data like URL's, endpoints, etc…
Toolbox for Automated API, Web and Mobile tests
In order to automate an API, a Web page, and a Mobile front-end, there are open source tools that will help you to quickly and easily build and run tests.
Tool for creating automated tests for an API (REST and XML). Uses an easily and understood DSL based on Gherkin (Given-When-Then).
In the example below it is possible to see the API through a local endpoint (simulating a production environment) and a mock endpoint created with Java Spark. Creating a mock API by developing the API fixed data returns can give even greater speed in the execution and validation of the different aspects that secure the tests for microservices, especially about contract tests.
It is the best-known tool for automation of a web page. It also has an easy DSL and is based on four steps for automation:
- Navigation: actions like access a web page, forward, back and refresh
- Interrogation: ways to find and web element like by id, name, cssSelectors and other locators
- Manipulation: a way to interact with an element like click, fill (sendKeys), clear and get text
- Synchronisation: ways to wait for some asynchronous actions, like an element that appears after some seconds
It is an open source tool with the same Selenium DSL, but for automation in native or hybrid mobile device apps for iOS or Android.
It supports execution on emulators, real device or test lab (cloud), and, in conjunction with Selenium Grid, gives the possibility of creating an internal device grid.
Applied Pipeline and GitHub Repo
The code for all projects can be found in the repository:
test-automation-javaone-2017 - An complete example of a pipeline focusing on API and UI (mobile and web) tests.github.com
There are test suites for each pipeline step.