Testers can write good code too. Corina

Similar documents
SeU Certified Selenium Engineer (CSE) Syllabus

SeU Certified Selenium Engineer (CSE) Syllabus

Advanced Java Testing. What s next?

SELENIUM. Courses Offered. Ph: / Course Coverage:- Date:..Timings.. Duration Fees. Testing Tools QTP Load Runner Hadoop

Selenium Testing Course Content

Jenkins: A complete solution. From Continuous Integration to Continuous Delivery For HSBC

Testing. Technion Institute of Technology Author: Assaf Israel. Author: Assaf Israel - Technion

Selenium. Duration: 50 hrs. Introduction to Automation. o Automating web application. o Automation challenges. o Automation life cycle

Automation Best Practices for CI/CD. Leo Laskin, Sr. Solutions Architect

Sonatype CLM - IDE User Guide. Sonatype CLM - IDE User Guide

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at

Introduction to Renjin The R interpreter in the JVM

The age of automation is going to be the age of 'do it yourself. - Marshall McLuhan

Checked and Unchecked Exceptions in Java

Testing. Topics. Types of Testing. Types of Testing

Section 4: Graphs and Testing. Slides by Erin Peach and Nick Carney

3.3 Web Graphics. 1. So why are graphics important?

*** Any Query *** Mail : 1. Introduction to Selenium. What is Selenium? Different automations tools. Selenium Automation Tools

Mind Q Systems Private Limited

lazy-object-proxy Release 1.3.1

CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L

Object Oriented Software Design - I

The Power of Unit Testing and it s impact on your business. Ashish Kumar Vice President, Engineering

Web Design and Usability. What is usability? CSE 190 M (Web Programming) Spring 2007 University of Washington

Getting Started with. Lite.

Java Programming Basics

Geo Catching Sprint #3 Kick-off

Archan. Release 2.0.1

Koenig Solutions Pvt. Ltd. Selenium with C#

Introduction to Automation. What is automation testing Advantages of Automation Testing How to learn any automation tool Types of Automation tools

Language alone won t pay your bills. Alan Franzoni - EP 2012 twitter: franzeur website:

IntelliJ IDEA Static Code Analysis Hamlet D'Arcy

Jenkins: AMPLab s Friendly Butler. He will build your projects so you don t have to!

Java. Error, Exception, and Event Handling. Error, exception and event handling. Error and exception handling in Java

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

CS159. Nathan Sprague

Introduction to the NetBeans Platform Certified Training Course. Geertjan Wielenga Sun Microsystems

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

Tuesday, November 15. Testing

Tools. SWE 432, Fall Design and Implementation of Software for the Web

About 1. Chapter 1: Getting started with cucumber 2. Remarks 2. Examples 3. A Cucumber feature 3. Pure Ruby Installation 4

Part 1: jquery & History of DOM Scripting

The Joy of Software Development

xtreme Programming (summary of Kent Beck s XP book) Stefan Resmerita, WS2015

Approach to development in OTM projects

COMP31212: Concurrency A Review of Java Concurrency. Giles Reger

GOING MOBILE: Setting The Scene for RTOs.

Intro. Scheme Basics. scm> 5 5. scm>

1. Selenium Integrated Development Environment (IDE) 2. Selenium Remote Control (RC) 3. Web Driver 4. Selenium Grid

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11


Sucuri Webinar Q&A HOW TO IDENTIFY AND FIX A HACKED WORDPRESS WEBSITE. Ben Martin - Remediation Team Lead

Unit Testing. CS 240 Advanced Programming Concepts

Creating A Visible Instructions Page In ICS

Shift Left Testing: are you ready? Live Webinar, Sept 19

Utilizing Fast Testing to Transform Java Development into an Agile, Quick Release, Low Risk Process

Exceptions and Design

Introduction to Renjin The R interpreter in the JVM. Maarten-Jan Kallen

Framework for Enhancing the Performance of Unit Testing in Java Based Projects

MySQL. The Right Database for GIS Sometimes

Test-Driven Development (a.k.a. Design to Test) CSE260, Computer Science B: Honors Stony Brook University

Maja Schreiner. 9th Lean, Agile & Scrum Conference 2017

All India Council For Research & Training

About 1. Chapter 1: Getting started with testng 2. Remarks 2. Versions 2. Examples 2. Installation or Setup 2. Quick program using TestNG 3

CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley

An architect s website:!

Abstract. Chapter 6 Writing a Program. Overview. Writing a program: Strategy. Building a program. Bjarne Stroustrup

Recipes. Marketing For Bloggers. List Building, Traffic, Money & More. A Free Guide by The Social Ms Page! 1 of! 24

Unit testing basics & more...

Section 4: Graphs and Testing

Video 2.1. Arvind Bhusnurmath. Property of Penn Engineering, Arvind Bhusnurmath. SD1x-2 1

Automated Testing of Tableau Dashboards

Syllabus Technosoft Academy. Course Syllabus. 1 P a g e

csc444h: so(ware engineering I matt medland

CSE 303: Concepts and Tools for Software Development

(Complete Package) We are ready to serve Latest Testing Trends, Are you ready to learn? New Batches Info

These are notes for the third lecture; if statements and loops.

2.6 Error, exception and event handling

JS Event Loop, Promises, Async Await etc. Slava Kim

Instructor Notes for 2 Days Java For Testers Training

cwmon-mysql Release 0.5.0

CS 3 Introduction to Software Engineering. 3: Exceptions

Java Review. Fundamentals of Computer Science

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Magento Technical Guidelines

SELENIUM TRAINING COURSE CONTENT

Testing and Debugging

A faster approach for accessing Snap Deal URL using Multi browser with Selenium Web Driver

On a blog, code can mean many things. It can refer to the complicated

Customizing the Blackboard Learn UI & Tag Libraries. George Kroner, Developer Relations Engineer

pytest-benchmark Release 2.5.0

Another Example. Other Constructs

Improve SSIS Delivery with a Patterns-Based Approach. Meagan Longoria July 19, 2017

In this lab we will practice creating, throwing and handling exceptions.

Poetaster. Release 0.1.1

CONTINUOUS INTEGRATION; TIPS & TRICKS

Google Analytics 101

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable

Unit testing. JUnit. JUnit and Eclipse. A JUnit test class 3/6/17. A method is flagged as a JUnit test case.

Expert Guidance on Migrating from Magento 1 to Magento 2

Transcription:

Testers can write good code too Corina Pip https://iamalittletester.wordpress.com/

Twitter: Blog: https://iamalittletester.wordpress.com/ Travel blog: https://travelwithcori.wordpress.com/ Photos: https://www.flickr.com/photos/capreoara GitHub: https://github.com/iamalittletester/learning-project

testers LOOOVE to write A LOT of code

WHAT WE WANT FROM OUR TEST CODE To not be just a sequence of assertions To follow coding standards To be easy to read

WHAT WE WANT FROM OUR TEST CODE To be easy to maintain To be beautiful Repeatable results

FIRST STEP OF WRITING CODE ANALYSIS Make sure requirements are clear Spend time identifying best solution Write, draw, visualize

PRINCIPLE 0: THE LAZY PRINCIPLE Write as little code as possible Write efficient code Don t reinvent the wheel Use existing libraries

CODE REVIEWS QA should be included in all code reviews QA should ask for QA and Dev to perform test code reviews Should be included in DoD

REFACTORING Refactoring IS allowed When you have a more optimal solution

NO WORKAROUND CODE If the environment is to blame for test failures Rather, have the environment fixed

SEPARATE PROD / DEV TESTS Ideally create separate code projects for production tests and dev tests No more: oops did I just run that in production? Production = lighter tests; possibly lighter configuration Dev = everything Better dependency management

JAVA

USE PROPER NAMING, FOR EVERYTHING Classes; methods; variables; constants; packages; modules Give them a relevant name Makes code easier to read Makes it easier to find stuff TestUtils vs DbDataUtils; avariable vs randomemailvalue

REUSE CODE, DON T COPY/PASTE IT Results in fewer lines of code Single point of change Easier maintenance Available to many tests Don t create a new method for one line of code

REUSE CODE, DON T COPY/PASTE IT Don t pass in too many parameters refactor Don t pass in constants make them local to methods Process parameters in method don t pass the whole processing as parameter If method is too long, maybe break it into several ones

MIND YOUR TRY/CATCHES Biggest cause of tests that should fail, but incorrectly don t! Source of invalid results: not properly configuring the try branch forgetting about the catch branch

MIND YOUR TRY/CATCHES use cases 1. Test should only pass if the exception is not thrown - equivalent to codetoberunhere; - only useful if you want to throw specific exception

MIND YOUR TRY/CATCHES use cases 2. Test should only pass if the exception is thrown

MIND YOUR TRY/CATCHES use cases 3. Test should pass no matter if the exception is thrown or not

OPTIMIZE YOUR IMPORTS Don t import * except when really needed Import static when needed Assert.assertEquals(..,..) assertequals(..,..) import static org.testng.assert.assertequals; Don t leave unused imports

VARIABLE SCOPES Define variables inside methods/blocks where they are used Define inline variables if you will use them just once

SIMPLIFY YOUR IFS variable = (conditiontobetrue)? valuewhentrue : valuewhenfalse if (somethingthatevaluatesasboolean is true) {return true;} else {return false;} REPLACE WITH: return somethingthatevaluatesasboolean;

PROPER CONSOLE OUTPUT Print test data to your console where needed Helps understand the state in which the tests are Helps get a step by step idea of how tests run Helps reproduce issue when you output the data used by the tests When no visibility of tests running (e.g. CI)

SEPARATION OF CONCERNS PRINCIPLE

SELENIUM

DON T SLEEP. WAIT FOR IT When you know your system under test is sluggish - wait before/for all the actions page load button to be clickable label to have certain text CSS attribute to have some value

WebDriverWait wait = new WebDriverWait(driver, TIMEOUT); ExpectedCondition thecondition = new ExpectedCondition<Boolean>() { public Boolean apply(webdriver arg0) { try { condition; return true; } catch (SomeException e ) { return false; } catch (AnotherException f) { return false; }}}; wait.until(thecondition);

DON T SLEEP. WAIT FOR IT Better to wait than fail Don t sleep: hard wait; will wait for exactly N seconds Do wait: flexibility; will wait UP to N seconds You even can replace asserts with waits

DON T CHECK ISDISPLAYED THEN INTERACT WebElements are initialized lazily element.isdisplayed(); element.click(); REPLACE with: element.click();

DON T HARDCODE BROWSER IN TESTS Should switch easily from one browser to the other Avoids any one browser/driver not working Tests should be browser unaware Use getter to retrieve WebElements (when different selectors on mobile vs desktop)

USE LISTS FOR SIMILAR ITEMS <ul> <li>coffee</li> <li>tea</li> <li>milk</li> </ul> webelement1 webelement2 webelement3 List<WebElement> list.get(0)

TESTNG

DON T DO ALL TEST DATA IN @BEFORECLASS Do not create ALL test data in @BeforeClass All tests depend on the full generation of the test data Running a single test needs to wait for ALL test data generation to be done If test data fails to generate in @BeforeClass, an exception is thrown and no test will run Running from testing.xml takes much longer

DON T DO ALL TEST DATA IN @BEFORECLASS Move test data generation into methods where possible Keep only common test data generation in @BeforeClass

SOME TOOLS

Maven: Checkstyle plugin (DEMO) Goal: fail the Maven build when poor code is found 2 step setup: Import Maven plugin into your project

Maven: Checkstyle plugin (DEMO) Create checkstyle.xml file contains a list of checks on the code Maven, Google and Sun checkstyle files Extract from a checkstyle file: Failure example: For reference please go to: https://iamalittletester.wordpress.com/2017/08/22/us ing-maven-checkstyle-in-your-project-to-help-adhereto-coding-standards/

IDE tools IntelliJ: Inspect code (DEMO) Refer to https://iamalittletester.wordpress.com/2015/07/12/improving-your-code-by-usingintellijs-inspections-feature/

IDE tools IntelliJ: Inspect code (DEMO) Refer to https://iamalittletester.wordpress.com/2015/07/12/improving-your-code-by-usingintellijs-inspections-feature/

KEEP UP WITH YOUR FRAMEWORK Constantly take a look at the new features released Read the changelogs Take a look at the features it offers, apart from the most commonly used by you

CONSTANT LEARNING Learn the programming languages / frameworks before writing code Learn how to improve the code you wrote

FIND GOOD SOURCES OF INFORMATION Start with the official documentation Developers Trust them Don t trust them (they change their mind a lot) Google, StackOverflow, etc: check the code properly before using it Twitter, blogs, books, conferences, workshops

THANK YOU! Twitter: Blog: https://iamalittletester.wordpress.com/ Travel blog: https://travelwithcori.wordpress.com/ Photos: https://www.flickr.com/photos/capreoara GitHub: https://github.com/iamalittletester/learning-project