Pages

Saturday, November 27, 2021

SOLID - Principles of Object Oriented Design

SOLID were introduced by Robert C. Martin, with intention that
When these principles are applied together , a programmer will create  a system which is easy to maintain and extend over time.
Can avoid:
Rigidity, Fragility, Immobility, Viscosity

Single Responsibility Principle
Open Closed Principle
Liskov Substitution Principle
Interface Segregation Principle (separation)
Dependency Inversion Principle

Single Responsibility:

A class should have one and only one responsibility. There cannot be more than one reason to change for a class. A class should have only one job to do. It should be cohesive (integrated) i.e. everything in class should be related to one purpose. 

Employee.java
public class Employee{
  private String employeeId;
  private String name;
  private string address;
  private Date dateOfJoining;
  public boolean isPromotionDueThisYear(){
    //promotion logic implementation
  }
  public Double calcIncomeTaxForCurrentYear(){
    //income tax logic implementation
  }
  //Getters & Setters for all the private attributes
}
Lets move the promotion determination logic from Employee class to the HRPromotions class like this


HRPromotions.java
public class HRPromotions{
  public boolean isPromotionDueThisYear(Employee emp){
    //promotion logic implementation using the employee information passed
  }
}
Similarly, lets move the income tax calculation logic from Employee class to FinITCalculations class –
FinITCalculations.java
public class FinITCalculations{
  public Double calcIncomeTaxForCurrentYear(Employee emp){
    //income tax logic implementation using the employee information passed
  }
}
Our Employee class now remains with a single responsibility of maintaining core employee attributes –
Employee.java adhering to Single Responsibility Principle
public class Employee{
  private String employeeId;
  private String name;
  private string address;
  private Date dateOfJoining;
  //Getters & Setters for all the private attributes
}




Open Closed Principle by Bertrand Meyer


Software entities should be open for extension but closed for modification.

It can be achieved by interfaces or abstract classes, rather than using concrete classes. Functionality can be added by creating new classes that implement the interfaces.

Your classes should be designed such a way that whenever fellow developers wants to change the flow of control in specific conditions in application, all they need to extend your class and override some functions and that’s it.

public class Rectangle
{
    public double Width { get; set; }
    public double Height { get; set; }
}public class AreaCalculator
{
    public double Area(Rectangle[] shapes)
    {
        double area = 0;
        foreach (var shape in shapes)
        {
            area += shape.Width*shape.Height;
        }

        return area;
    }
}public double Area(object[] shapes)
{
    double area = 0;
    foreach (var shape in shapes)
    {
        if (shape is Rectangle)
        {
            Rectangle rectangle = (Rectangle) shape;
            area += rectangle.Width*rectangle.Height;
        }
        else
        {
            Circle circle = (Circle)shape;
            area += circle.Radius * circle.Radius * Math.PI;
        }
    }

    return area;
}



“extending the AreaCalculator class to also calculate the area of triangles isn’t very hard, is it?”. Of course in this very basic scenario it isn’t but it does require us to modify the code. That is, AreaCalculator isn’t closed for modification as we need to change it in order to extend it. Or in other words: it isn’t open for extension.

A solution that abides by the Open/Closed Principle

public abstract class Shape
{
    public abstract double Area();
}public class Rectangle : Shape
{
    public double Width { get; set; }
    public double Height { get; set; }
    public override double Area()
    {
        return Width*Height;
    }
}public class Circle : Shape
{
    public double Radius { get; set; }
    public override double Area()
    {
        return Radius*Radius*Math.PI;
    }
}public double Area(Shape[] shapes)
{
    double area = 0;
    foreach (var shape in shapes)
    {
        area += shape.Area();
    }

    return area;
}

Liskov Substitution Principle 

objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.

If the subtype is not replaceable for the supertype reference, then in order to support the subtype instances as well we go ahead and make changes to the existing code and add the support. This is a clear violation of OCP.



class Bird {
  public void fly(){}
  public void eat(){}
}
class Crow extends Bird {}
class Ostrich extends Bird{
  fly(){
    throw new UnsupportedOperationException();
  }
}
 
public BirdTest{
  public static void main(String[] args){
    List<Bird> birdList = new ArrayList<Bird>();
    birdList.add(new Bird());
    birdList.add(new Crow());
    birdList.add(new Ostrich());
    letTheBirdsFly ( birdList );
  }
  static void letTheBirdsFly ( List<Bird> birdList ){
    for ( Bird b : birdList ) {
      b.fly();
    }
  }
}

As soon as an Ostrich instance is passed, it blows up!!! Here the sub type is not replaceable for the super type.


In the above scenario we can factor out the fly feature into- Flight and NonFlight birds.
class Bird{
  public void eat(){}
}
class FlightBird extends Bird{
  public void fly()()
}
class NonFlight extends Bird{}

















Integration Segregation Principle 

Many client specific interfaces are better than one general purpose interface



Monday, February 9, 2015

Automation Coding Standards and Best Practice

1. Introduction:

The purpose of these guidelines is to provide coding style standards for the development of source code for automation testing written in java. Adhering to a coding style standard is an industry proven best practice for making team development more efficient and application maintenance more cost-effective. While not comprehensive, these guidelines represent the minimum level of standardization expected in the source code of projects written in java.

This document describes rules and recommendations for developing applications and class libraries. The goal is to define guidelines to enforce consistent style and formatting and help automation testers to avoid common pitfalls and mistakes.

2. Terminology and Definitions

2.1  Access Modifier

Java keywords public, protected, package (default), and private declare the allowed code-accessibility of types and their members. Although default access modifiers vary, classes and most other members use the default of private.
Public: No restricted access.
Protected: Access is limited to subclasses in other package or any class within the package of the protected members' class.
Package (default): Access is limited to only within package.
Private: Access is limited to within the class definition

2.2 General Naming Conventions in Java

Camel Case
A word with the first letter lowercase, and the first letter of each subsequent word-part capitalized.
Example: customername

Pascal Case
A word with the first letter capitalized, and the first letter of each subsequent word-part capitalized.
Example: customername

Lowercase
Where all the letters in a word are written without any capitalization
Example: while, if, mypackage

Uppercase
Where all the letters in a word are written in capitals. When there are more than two words in the name use underscores to separate them.
Example: MAX_HOURS, FIRST_DAY_OF_WEEK

Mixed Case
It is same as Camel Case except the first letter of the name is in lowercase
Example:  haschildren, customerfirstname, customerlastname

Entity

Pattern

Examples

Package
Lowercase
org.company.test.SampleTest
Class, Enum & Interface
Camelcase
Class testcase
Interface basetest
Construction
Camelcase
(Same as Class Name)
Public testcase()
Methods
Mixedcase
Gettestcasename()
Variables
Mixedcase
String testcasename;
Constants
Uppercase
Public static final String URL

2.3 Standard Java naming conventions

Refer below URL:


2.4 Commenting Conventions:

  • Implementation comments are delimited by /*...*/, and //.
  • Comments should be used to give overviews of code and provide additional information that is not readily available in the code itself. Comments should contain only information that is relevant to reading and understanding the program.
  • All Classes should have beginning comment (c-type comment) that precisely describes the function of class

 3. Standard project structure

3.1 Solution & project naming convention

  •   Do not use the java reserved keywords in project name.
  •   Do not use acronyms that are not generally accepted in the computing field.
  •   When using acronyms, use pascal case for more than two characters long.
  •   Do not use spaces or other characters such as: ! # $ % & ' @ ^ ` ~ + , . ; = )

3.2 Directory structure:

  • The src directory contains all java files and is a place holder for other java files like listener, pages, resources, tests, utility, config
  • The config folder is a place holder for properties files.
  • The lib directory contains required jar files, and is a place holder for other library jars/zips.
  • The resources directory contains all required resources including properties files and data files, and is a place holder for other resources.
  • The server directory contains selenium server jar/ chromedriver.exe/ iedriverserver.exe
  • The test-output directory contains result files.
  • The testng.xml file, to run test cases.
  • Screenshots contains captures of pages where assertion failed.

3.3 Source code would be divided in below parts:

  • Test classes: defines methods for test cases/scenarios. These method will have @test annotation
  • Test page : define methods for interacting with page that includes filling data, accessing ui component, reading data from page, basic actions performed on page
  • Utility classes : defines methods for other aiding functionalities


Sunday, December 14, 2014

Ant in selenium

Lets understand ANT Terminology:

1.<Project> : 
   It is top level element in the ANT Script
   It is has three optional attributes:
   a.name b.default c.basedir
   a.name:  need to define the name of the project
   b.default: default target use when no other target to supplied
   c.basedir: It is where all path calculation are done

2.Target:
   It is set of the task which you want to be executed.
   Each project can be define zero or more target.Target can be depend on the another target.
   Project can be have zero or more targets. when no target is given the project use the default target.
   When the starting the ANT you can choose whichever target you want to be executed. 
   The main Targets are:
   1.Clean:  Clean up
   2.Compile: Compile the source code
   3.Dist: Generate the distribution

 3.Task: 
    It is piece of the code which can be executed.It has multiple attributes.
    There are so many task written for ANT.
    ANT Task:
    1.File Task:  File task are copy,concat,mkdir,delete,get,replace,move,tempfile etc.
    2.Compile Task: Compile task are javac,apt,rmic
    3.Archive Task: Archive task are zip-unzip,jar-unjar,war-unwar 
    4.Testing Task:  Teasting Task are junit,junitreport
    5.Property Task: Property task are dirname,loadfile,propertyfile,uptodate
    6.There are some other task are there like echo,javadoc,sql 

4.Properties:
   It has a name and a value,it's case sensitive.
   The property name specify between the "${"property-name"}" and attribute value too.

Pareto Principle- 80–20 rule of automation testing


80-20 rule that says that 80% of the results are coming from 20% of the subjects.
 
This is a good rule of thumb for determining how much testing is enough. 
you can typically test approximately 80% of the functionality that people actually use by focusing on 20% of the possible test combinations.

This can be applied to any field as follows:

- 80% of the revenue of a company is coming from 20% of the clients

- 80% of the donations for a charity are coming from 20% of the people

- 80% of the books from a bookstore are purchased by 20% of the clients

- 80% of the clients are using 20% of the functionality

- 80% of the bugs are caused by 20% of the functionality

Microsoft noted that by fixing the top 20% of the most-reported bugs, 80% of the related errors and crashes in a given system would be eliminated
In load testing, it is common practice to estimate that 80% of the traffic occurs during 20% of the time

How does this apply to testing?

Well, the project release date is fixed so you cannot test everything well.

So, test only 20% of the application as this is what the majority of the users will use.

Select the 20% of the application's functionalities that have the highest risk and test them well.

Test the remaining 80% of the functionalities by just taking the happy paths.

You think you did a good job, the project manager is happy with the results.

And after the release, the support team receives lots of issues from the clients about the 80% of the application not tested well.

More, the senior management of the company starts noticing problems all over the application too.

The solution is, of course, applying an endless number of patches with bug fixes for the issues discovered by the customers, frustrating the customers as much as possible and wasting as much time as possible for both the development and testing team.

Severity and Priority

Severity and Priority


  • Severity is about the risk if a bug poses. Severity is related to Technical aspects:


  • Priority is related to Business aspect:

    Most organizations have standard criteria for classifying bug severity, such as:

  • Severity 1 – Catastrophic bug or showstopper. Causes system crash, data corruption, irreparable harm, etc.
  • Severity 2 – Critical bug in important function. No reasonable workaround.
  • Severity 3 – Major bugs but has viable workaround.
  • Severity 4 – Minor bug with trivial impact.


Typically, Severity 1 and 2 bugs must be fixed before release, where 3’s and 4’s might not be, depending on how many we have and on plans for their subsequent disposition.



Testing Models

Let us discuss and explore into few of the famous models. 

The following models are addressed: 
  1. Waterfall Model.
  2. Spiral Model. 
  3. 'V' Model. 
  4. 'W' Model, and 
  5. Butterfly Model. 

The Waterfall Model 
This is one of the first models of software development, presented by B.W.Boehm. The Waterfall model is a step-by-step method of achieving tasks. Using this model, one can get on to the next phase of development activity only after completing the current phase. Also one can go back only to the immediate previous phase.
In Waterfall Model each phase of the development activity is followed by the Verification and Validation activities. One phase is completed with the testing activities, then the team proceeds to the next phase. At any point of time, we can move only one step to the immediate previous phase. For example, one cannot move from the Testing phase to the Design phase. 

Spiral Model 
In the Spiral Model, a cyclical and prototyping view of software development is shown. Test are explicitly mentioned (risk analysis, validation of requirements and of the development) and the test phase is divided into stages. The test activities include module, integration and acceptance tests. However, in this model the testing also follows the coding. The exception to this is that the test plan should be constructed after the design of the system. The spiral model also identifies no activities associated with the removal of defects. 

'V' Model

Many of the process models currently used can be more generally connected by the 'V' model where the 'V' describes the graphical arrangement of the individual phases. The 'V' is also a synonym for Verification and Validation.
By the ordering of activities in time sequence and with abstraction levels the connection between development and test activities becomes clear. Oppositely laying activities complement one another (i.e.) server as a base for test activities. For example, the system test is carried out on the basis of the results specification phase. 

The 'W' Model
From the testing point of view, all of the models are deficient in various ways:
The Test activities first start after the implementation. The connection between the various test stages and the basis for the test is not clear.
The tight link between test, debug and change tasks during the test phase is not clear.

Why 'W' Model? 
In the models presented above, there usually appears an unattractive task to be carried out after coding. In order to place testing on an equal footing, a second 'V' dedicated to testing is integrated into the model. Both 'V's put together give the 'W' of the 'W-Model'. 

Butterfly Model of Test Development
Butterflies are composed of three pieces – two wings and a body. Each part represents a piece of software testing, as described hereafter

Test Case

Test Case is nothing but it shows your defined activities and steps which you will perform in your testing. 

In Manual testing test case is written manually but in automation testing it is generated by testing tools and is known as Test Script. Test Case and Test Script both are same because both of them perform same activities but has only one difference that test case is written in simple sentences and test script is generated in form script. Script is light weight programming language.

Test case Format:

Test case ID: Unique ID for each test case. Follow some convention to indicate types of test. E.g. ‘TC_Module_SubModule_01′

Test priority (Low/Medium/High): This is useful while test execution. Test priority should be set by reviewer.

Module Name – Mention name of main module or sub module.

Test Designed By: Name of tester

Test Designed Date: Date when wrote

Test Executed By: Name of tester who executed this test. To be filled after test execution.

Test Execution Date: Date when test executed.

Test Objective/Description: Describe test objective in brief.

Pre-condition: Any prerequisite that must be fulfilled before execution of this test case. List all pre-conditions in order to successfully execute this test case.

Dependencies: Mention any dependencies on other test cases or test requirement.

Test Steps: Write every Action and corresponding result in Expected Result

Test Data: Use of test data as an input for this test case.

Expected Result:   Describe the expected result in detail including message/error that should be displayed on screen for your every action.

Post-condition: What should be the state of the system after executing this test case?


Actual result: Actual test result should be filled after test execution.

Status (Pass/Fail): If actual result is not as per the expected result mark this test as failed. Otherwise update as passed.

Notes/Comments/Questions: To support above fields if there are some special conditions which can’t be described in any of the above fields or there are questions related to expected or actual results mention those here.

Add following fields if necessary:

Defect ID/Link: If test status is fail, then include the link to defect log or mention the defect number.

Test Type/Keywords: This field can be used to classify tests based on test types. E.g. functional, usability, business rules etc.

Requirements: Requirements for which this test case is being written. Preferably the exact section number of the requirement doc.

Attachments/References: This field is useful for complex test scenarios. To explain test steps or expected result using a visio diagram as a reference. Provide the link or location to the actual path of the diagram or document.


Automation? (Yes/No): Whether this test case is automated or not. Useful to track automation status when test cases are automated.

Bug Life Cycle

Introduction:
Bug can be defined as the abnormal behavior of the software. No software exists without a bug.

A mistake in coding is called error ,error found by a tester is called defect,  defect accepted by development team then it is called bug ,build does not meet the requirements then it is failure.

Bug Life Cycle:
In software development process, the bug has a life cycle. The bug should go through the life cycle to be closed. A specific life cycle ensures that the process is standardized. The bug attains different states in the life cycle. The life cycle of the bug can be shown diagrammatically as follows:


The different states of a bug can be summarized as follows:


1. New
2. Open
3. Assign
4. Test
5. Verified
6. Deferred
7. Reopened
8. Duplicate
9. Rejected and
10. Closed

Description of Various Stages:
1. New: When the bug is posted for the first time, its state will be “NEW”. This means that the bug is not yet approved.

2. Open: After a tester has posted a bug, the lead of the tester approves that the bug is genuine and he changes the state as “OPEN”.

3. Assign: Once the lead changes the state as “OPEN”, he assigns the bug to corresponding developer or developer team. The state of the bug now is changed to “ASSIGN”.

4. Test: Once the developer fixes the bug, he has to assign the bug to the testing team for next round of testing. Before he releases the software with bug fixed, he changes the state of bug to “TEST”. It specifies that the bug has been fixed and is released to testing team.

5. Deferred: The bug, changed to deferred state means the bug is expected to be fixed in next releases. The reasons for changing the bug to this state have many factors. Some of them are priority of the bug may be low, lack of time for the release or the bug may not have major effect on the software.

6. Rejected: If the developer feels that the bug is not genuine, he rejects the bug. Then the state of the bug is changed to “REJECTED”.

7. Duplicate: If the bug is repeated twice or the two bugs mention the same concept of the bug, then one bug status is changed to “DUPLICATE”.

8. Verified: Once the bug is fixed and the status is changed to “TEST”, the tester tests the bug. If the bug is not present in the software, he approves that the bug is fixed and changes the status to “VERIFIED”.

9. Reopened: If the bug still exists even after the bug is fixed by the developer, the tester changes the status to “REOPENED”. The bug traverses the life cycle once again.

10. Closed: Once the bug is fixed, it is tested by the tester. If the tester feels that the bug no longer exists in the software, he changes the status of the bug to “CLOSED”. This state means that the bug is fixed, tested and approved.

While defect prevention is much more effective and efficient in reducing the number of defects, most organization conducts defect discovery and removal. Discovering and removing defects is an expensive and inefficient process. It is much more efficient for an organization to conduct activities that prevent defects.

Guidelines on deciding the Severity of Bug:
Indicate the impact each defect has on testing efforts or users and administrators of the application under test. This information is used by developers and management as thebasis for assigning priority of work on defects.

A sample guideline for assignment of Priority Levels during the product test phase includes:

  1. Critical / Show Stopper — An item that prevents further testing of the product or function under test can be classified as Critical Bug. No workaround is possible for such bugs. Examples of this include a missing menu option or security permission required to access a function under test.
    .
  2. Major / High — A defect that does not function as expected/designed or cause other functionality to fail to meet requirements can be classified as Major Bug. The workaround can be provided for such bugs. Examples of this include inaccurate calculations; the wrong field being updated, etc.
    .
  3. Average / Medium — The defects which do not conform to standards and conventions can be classified as Medium Bugs. Easy workarounds exists to achieve functionality objectives. Examples include matching visual and text links which lead to different end points.
    .
  4. Minor / Low — Cosmetic defects which does not affect the functionality of the system can be classified as Minor Bugs.

Roles and Responsibilities for Sr Quality Analyst (Automation)

Roles and Responsibilities for Sr Quality Analyst (Automation)

·  Prepare Reusable functions, which improve the robustness, re-usability, and maintainability of their test scripts.
·  The framework should be designed in such a way that it increases and speeds up their productivity.
·  The engineer also must support the framework/s, for example, supporting dev/qa with issues using the tool. The engineer will implement automation test scripts. Integration with the test management tool is also, planned.
·  The Senior Test Automation Engineer must be able to take on leadership responsibilities and influence the direction of the automation effort, and its schedule and prioritization.
·  The engineer will work with management, developers, and quality assurance personnel, to meet these goals.
·  Additionally the Test Automation Engineer will also be involved in supporting the build master implement/improve build test processes, environments, and scripts. These build tests ensure that the code drops to quality assurance are of the highest quality.

·  He will provide a practical approach to complex product testing,  in the areas of the automation of test cases for the purposes of regression testing.
· He will be a creative and proactive thinker and you will make use of current technologies to provide extensible automation infrastructures.
·  He will review product requirements, functional and design specifications to determine and prepare automated test cases.
·  He will work closely with other QC team members to automate the execution and verification of reports created by the various company products.
·  He will be part of a team focusing on automation of an identified set of migration tests, checking they run correctly and working within the infrastructure. The team would focus on develop and test these automation buckets which would be executed by other teams