ivan pashko - simplifying test automation with design patterns
TRANSCRIPT
![Page 1: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/1.jpg)
Simplifying test automation with design patterns
Ivan Pashko
![Page 2: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/2.jpg)
Speaker info
Ivan Pashko, UkraineScrum Master in Betsson, Ciklum
• 8+ years in the IT
• Software Automation Developer
/in/ivan-pashko-33208042/
/groups/1180099188730673
![Page 3: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/3.jpg)
Code smell
![Page 4: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/4.jpg)
Clean code
Code is clean if it can be understood
easily – by everyone on the team, going
over a long time
![Page 5: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/5.jpg)
![Page 6: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/6.jpg)
Why Design Patterns?
General repeatable solution to a commonly occurring
problem in software design.
![Page 7: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/7.jpg)
Test smells
• Test Code Duplication• Conditional Test Logic• Obscure Test• Fragile Test
![Page 8: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/8.jpg)
Test smells
• copy/paste• if-else • inheritance /overrides• data sensivity (hardcode, magic values)
![Page 9: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/9.jpg)
Test smell. Copy/Paste
• Duplication increasesthe cost of maintenance
![Page 10: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/10.jpg)
Template Method
• Defines the skeleton of an algorithm in an operation,
• Deferring some steps to subclasses
![Page 11: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/11.jpg)
Template Method
public class MonitoringNotificationBaseTest<T> where T : BaseNotificationData
/// <summary>
/// Method perform next steps:
/// 1. Create New Notification
/// 2. Update Notification
/// 3. Check Enable/Disable Button
/// 4. Remove Notification
/// </summary>
/// <param name="defaultNotification">Used in 1 step</param>
/// <param name="updatedNotification">Used in 2 step</param>
public void CRUDNotificationTest(T defaultNotification, T updatedNotification)
{
CreateNewNotification(defaultNotification);
UpdateNotification(updatedNotification);
CheckEnableDisableButton();
RemoveNotification();
}
![Page 12: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/12.jpg)
Test smell. Conditional Test Logic
Makes tests more complicated than
they really should be.
![Page 13: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/13.jpg)
if (element.Exist()){
AssertElementContext(element);}else{
AssertErrorMessageAppeared();}
if (element != null)
{
element.Click();
}
• What condition is passed?
• What if condition failed, but test is green?
• What is test fail?
Test smell. Conditional Test Logic
![Page 14: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/14.jpg)
Strategy Pattern
Enables an algorithm's behavior to be selected at
runtime
![Page 15: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/15.jpg)
Factory Pattern
• Hides the logic of initializing an object inside the factory.
• Refers to the object using a common interface instead of the concrete class.
![Page 16: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/16.jpg)
Test smell. Inheritance /overrides
Blind inheritance and overrides leads to the creation of «Monster» objects
![Page 17: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/17.jpg)
Composite Pattern
• The composite pattern describes a group of objects that is treated the same way as a single instance of the same type of object.
![Page 18: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/18.jpg)
Decorator Pattern
• Attach additional responsibilities to an object dynamically.
![Page 19: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/19.jpg)
• Revealing Naming
• Replace Magic Numbers with constants
• Use builder for defaults & complex object creation
//Revealing namingList<string> list1List<string> userNames
//Magic numbers as constantsFindByAge(33);
const int OLD_USER_AGE = 33;FindByAge(OLD_USER_AGE);
Test smell. Data sensitivity
![Page 20: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/20.jpg)
Builder Pattern
Separates the construction of a complex object from its representation
![Page 21: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/21.jpg)
Builder Pattern
public class User{
//Required parameters:public string Email { get; set; }public string Login { get; set; }
//Additional parameters:public string Name { get; set; }public int Age { get; set; }public string Address { get; set; }
}
• Typical test user object:• Required fields• Additional fields
![Page 22: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/22.jpg)
Builder Pattern
//Telescoping constructornew User(email, login);new User(email, login, "test name", 18, "test address");
//JavaBeansnew User("[email protected]", "test_123"){
Name = "Name",Age = 18,Address = "test address"
};
• Copy / paste
• Constructor overrides
• Helpers methods
As a result:
• A lot of code
• Duplicates
• Unclear defaults
![Page 23: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/23.jpg)
Builder Patternnew UserBuilder("[email protected]", "user_123")
.Name("Name")
.Age(18)
.Address("test address")
.Build();
public UserBuilder(string email, string login){
_user = new User(email, login){
//Default values:Name = "Default Name",Age = 18,Address = "Default address"
};}
• Easy to read
• Simple to extend
• Safe defaults
![Page 24: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/24.jpg)
Your test smells if
• contains if’s
• has a ‘twin brother’
• depends on the data
• doesn’t feet in one screen
• bypass your framework
![Page 25: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/25.jpg)
Good testis like a
good joke
- it needs no explanation
![Page 26: Ivan Pashko - Simplifying test automation with design patterns](https://reader031.vdocuments.mx/reader031/viewer/2022030318/5a649fc77f8b9a31568b5b4d/html5/thumbnails/26.jpg)
Thank you
Useful links:
http://blog.bbv.ch/wp-content/uploads/2013/06/Clean-Code-V2.1.pdf
http://xunitpatterns.com
https://sourcemaking.com
Questions?
You can also ask questions for me in the lounge zone