Top Banner
42

Software Design Patterns in Test Automation

Jan 18, 2018

Download

Documents

Theresa Lucas

Software Design Patterns in Test Automation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Software Design  Patterns in Test  Automation
Page 2: Software Design  Patterns in Test  Automation

Software Design Patterns in Test Automation

Page 3: Software Design  Patterns in Test  Automation

3

1. Objectives2. What are Design Patterns?3. Design Pattern and Design Principle - what's the difference?4. Principles KISS Don’t Repeat Yourself.5. Patterns Multi-layered test solution Facade Chaining Template Method

Table of Content

Page 4: Software Design  Patterns in Test  Automation

Objectives• Present the concepts of „design pattern” & „de-sign principle” • Show why these concepts are important• Describe chosen patterns & principles.• All presented patterns have examples in C# but can be used with most Object-Oriented Languages• Target Audience: Testers who are writing automated tests and want to dive deeper into programing world.

Page 5: Software Design  Patterns in Test  Automation

5

• General reusable solution to a commonly occuring problem within given context• Object-Oriented Desgin Patterns typically show relationships between classes and objects without specifing theirs final application.• (a pattern) „describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same ay twice„- Christopher Alexander

Software Design Pattern

Page 6: Software Design  Patterns in Test  Automation

6

• Software Design Principle - Set of Guidelines that helps to avoid bad design and unmaintainable code.• „Design principles are the desirable goals that one aims to achieve. Design patterns are tools one can use to realize those goals. ” – E Arimitage

Pattern vs Principle

Page 7: Software Design  Patterns in Test  Automation

Keep it simple stupid. (KISS)KISS

Page 8: Software Design  Patterns in Test  Automation

KISS – Example 8

Page 9: Software Design  Patterns in Test  Automation

9KISS – Example

Page 10: Software Design  Patterns in Test  Automation

Solution

Page 11: Software Design  Patterns in Test  Automation

Don’t Repeat yourself (DRY)

DRY

Page 12: Software Design  Patterns in Test  Automation

12DRY - Example

Page 13: Software Design  Patterns in Test  Automation

Solution

Page 14: Software Design  Patterns in Test  Automation

Time for Patterns

Page 15: Software Design  Patterns in Test  Automation

Multi Layered Test SolutionStrategy

Page 16: Software Design  Patterns in Test  Automation

Overview

Page 17: Software Design  Patterns in Test  Automation

Example

Page 18: Software Design  Patterns in Test  Automation

Pros & Cons• Low maintenance effort and time• Enhanced code reusability• Structured codebase which is easy to fix and extend• Improved communication• Complexity• Time invested during creation• Experience

Page 19: Software Design  Patterns in Test  Automation

FacadeFacade

Page 20: Software Design  Patterns in Test  Automation

20Facade – description

Facade provides an unified interface in subsystem. Defines a higher-level interface that makes the subsystem easier to use.

Page 21: Software Design  Patterns in Test  Automation

Facade – UML

Page 22: Software Design  Patterns in Test  Automation

Facade - Test Case

• Login as Normal User • Add product to cart • Go to checkout• Verify if PayPal is available payment method

Page 23: Software Design  Patterns in Test  Automation

Facade – Before

Page 24: Software Design  Patterns in Test  Automation

Facade –After

Page 25: Software Design  Patterns in Test  Automation

Facade – Front Facade Implementation

Page 26: Software Design  Patterns in Test  Automation

Pros & Cons

• Less time spent on writing new test cases • Easier maintenance.• Test is harder to debug if it fails in ‚unexpected’ way.• Test is unreadable – if treated as an Unit Test.

Page 27: Software Design  Patterns in Test  Automation

Methods Chaining

Page 28: Software Design  Patterns in Test  Automation

Methods Chaining- Example

Page 29: Software Design  Patterns in Test  Automation

Chaining – methods difference

Page 30: Software Design  Patterns in Test  Automation

Pros & Cons

Helps when writing testsClean Code & ReadabilityPerson can’t see what object is returnedChain breaks

Page 31: Software Design  Patterns in Test  Automation

Template Method

Page 32: Software Design  Patterns in Test  Automation

32Template Method– description

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

Page 33: Software Design  Patterns in Test  Automation

Template Method– UML

Page 34: Software Design  Patterns in Test  Automation

Template Method -Test Cases

Buy Product Go To CheckoutValidate PayPal PaymentBuy Product Go To CheckoutValidate Payment On Delivery

Page 35: Software Design  Patterns in Test  Automation

Template Method - Example

Page 36: Software Design  Patterns in Test  Automation

Template Method - Example

Page 37: Software Design  Patterns in Test  Automation

Pros & Cons• Avoiding God Class• Modularization• Quite hard to understand• To understand what going on in test ‚little digging’ is neccesary

Page 38: Software Design  Patterns in Test  Automation

SummaryDesign patterns are more like guidelinesPatterns can be bad if used in wrong con-textAnybody can use themDo not force patterns into your code!!!Anti-Patterns

Page 39: Software Design  Patterns in Test  Automation

Bibliographyhttp://dofactory.com/net/design-patternsHead First Design Patterns – O’Reily MediaDesign Patterns: Elements of Reusable Object-Oriented Software

Page 40: Software Design  Patterns in Test  Automation

Questions?

Page 41: Software Design  Patterns in Test  Automation

Contact Us

[email protected]@gmail.com

Page 42: Software Design  Patterns in Test  Automation

Thank you for your attentionKrzysztof Wilczyński & Maciej Wyrodek