This document summarizes the author's journey with test automation and lessons learned. It discusses using the driver pattern to clean up complicated test logic, abstract implementation from business logic, and make tests reusable. It also discusses using page object pattern for graphical user interface testing, similarly encapsulating selector logic. The author advocates for testers and programmers to work together, treating automation as a craft to develop over time, and ensuring quality by maintaining tests to avoid technical debt later on.
21. @Test shouldRetrieveUserByLogin() {
String userJson = "{"username": "vaidas"}";
HttpRequest post = new Post("https://localhost:8080/users", userJson);
HttpResponse postResp = HttpClient().execute(post);
assertThat(postResp.status, is(200));
HttpRequest get = new Get("https://localhost:8080/users/vaidas");
HttpResponse getResp = HttpClient().execute(get);
User user = mapper.readValue(getResp, User.class);
assertThat(username, is("vaidas"));
}
22. Few problems with such test
● Business requirements are mixed
within implementation
● URLs are hardcoded
● Payload format is hardcoded
● Test exposes use of HTTP protocol
24. Driver pattern
● Abstracts implementation from business logic
● Removes duplication
● Test specification becomes reusable
25. So, what if there’s a need to...
● Add another protocol (http + https)
● Another input format
● Test with different configuration
● Customize for different clients
26. InternetBankApiTest extends BankApiTest
with InternetBankDriver
with InternetBankApiMatchers
AtmApiTest extends BankApiTest
with AtmDriver
with AtmMatchers
Depending on your programming language:
● Use inheritance or composition
● Java 8 has default method in interfaces
● Consider using another language - JavaScript, Groovy,
Scala, etc
27. What if there is difference
between two implementations?
● Override tests by extending the contract class
● Use class hierarchy to group tests into
reusable test suites
28. Page Object pattern
● Is a variant of Driver pattern
● Selenium best practice
● encapsulates selector logic
● Solves the same problem as using drivers with
API testing
● Does not have to be per page, but per
component
29. Test patterns summary
● Use Driver Pattern for Microservice/API
● Use Page Object for graphical interface
30.
31. Lessons learnt
• Testers should not work separately from
programmers
• Quality matters
• Allocate time to maintain tests
• Or later it will cost €
32. Summary
● Do more pairing
● Treat automation as a craft
● Regular feedback is a must