Tuesday, December 23, 2014

Java: Exception Handling

Java Exception-

A Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of code

When an exceptional condition arises, an object representing that exception is created and thrown in the method that caused the error that means at some point, the exception is caught and processed.

Handling Exceptions-

There are two ways for handling exception-
First catch the exception and take corrective action
or
Throws exception to the calling method which will forces the calling method to handle it

Method#1- Catch the exception and take corrective action

public class DivideExceptionHandle {

    public static void main(String[] args) {
       
        Scanner inputDevice = new Scanner(System.in);
        System.out.print("Please enter first number(numerator): ");
        int numerator = inputDevice.nextInt();
        System.out.print("Please enter second number(denominator): ");
        int denominator = inputDevice.nextInt();        
        new DivideExceptionHandle().doDivide(numerator, denominator);      
    }
   
    public void doDivide(int a, int b){
        try{  
            float result = a/b;  
            System.out.println("Division result of "+ a +"/"+b +"= " +result);  
        }catch(ArithmeticException e){  
            System.out.println("Exception Condition Program is ending ");  
        }
    }
}

Method# 2- Throws exception to the calling method which will forces the calling method to handle it

public class DivideExceptionThrows {

    public static void main(String[] args){
       
        Scanner inputDevice = new Scanner(System.in);
        System.out.print("Please enter first number(numerator): ");
        int numerator = inputDevice.nextInt();
        System.out.print("Please enter second number(denominator): ");
        int denominator = inputDevice.nextInt();        
        try {  
            new DivideExceptionThrows().doDivide(numerator, denominator);  
        } catch (Exception e) {  
            System.out.println("Exception Condition Program is ending ");  
        }      
    }
   
    public void doDivide(int a, int b) throws Exception{
            float result = a/b;
            System.out.println("Division result of "+ a +"/"+b +"= " +result);
    }
}
}

Use of Finally block


When you have actions you must perform at the end of a try...catch sequence, you can use a finally block.

The code within a finally block executes regardless of whether the preceding try block identifies an Exception.

Usually, you use a finally block to perform cleanup tasks e.g. In application where database connection, files are being operated, we need to take of closing those resources in exceptional condition as well as normal condition

Following example shows how finally works-

import java.util.*;

class Test
    {
    public static void main(String[] args) throws Exception
        {
       
        try
            {
            BadMethod();
           System.out.println("A");
        }
        catch(ArithmeticException e)
        {
            System.out.println("Test");
        }
        catch(Exception e)
            {
            System.out.println("Bad Input");
        }
        finally
            {
            System.out.println("C");
        }
        System.out.println("D");
    }
    public static void BadMethod()
        {}
}

Output- 
A
C
D

Nested Try-Catch Block

We can always catch some exception specifically which can occur and use java run time system to handle the other exceptions. But we need to make sure that super class Exception should come in the last catch else you will get a compile time error e.g. Following code will throw error


import java.util.*;

class Test
    {
    public static void main(String[] args) throws Exception
        {
        int a=5, b=0;
        try
            {
               System.out.println(a/b);     
        }
        
        catch(Exception e)
            {
            System.out.println("Bad Input");
        }
         catch(ArithmeticException e)
        {
            System.out.println("Test");
        }
    }
}

error: exception ArithmeticException has already been caught

Following is the fix for above code-

import java.util.*;

class Test
    {
    public static void main(String[] args) throws Exception
        {
        int a=5, b=0;
        try
            {
           System.out.println(a/b);
        }
        catch(ArithmeticException e)
        {
            System.out.println("Test");
        }
        catch(Exception e)
            {
            System.out.println("Bad Input");
        }      
    }

}

Output- Test

Friday, November 21, 2014

Boundary value analysis & equivalence Partitioning with Example

Equivalence Partitioning:
In this method the input domain data is divided into different equivalence data classes
Boundary value analysis:
‘Boundary value analysis’ testing technique is used to identify errors at boundaries rather than finding those exist in center of input domain
E.g.: If you are testing for an input box accepting numbers from 1 to 1000 then- 
Test cases for input box accepting numbers between 1 and 1000 using Equivalence Partitioning:
1) One input data class with all valid inputs. Pick a single value from range 1 to 1000 as a valid test case. If you select other values between 1 and 1000 then result is going to be same. So one test case for valid input data should be sufficient.
2) Input data class with all values below lower limit. I.e. any value below 1, as a invalid input data test case.
3) Input data with any value greater than 1000 to represent third invalid input class.
Test cases for input box accepting numbers between 1 and 1000 using Boundary value analysis:
1) Test cases with test data exactly as the input boundaries of input domain i.e. values 1 and 1000 in our case.
------------
2) Test data with values just below the extreme edges of input domains i.e. values 0 and 999.
3) Test data with values just above the extreme edges of input domain i.e. values 2 and 1001.

Agile And Scrum

Agile model, Scrum
     Agile:
    # based on iterative and incremental development
    # Customer satisfaction by rapid delivery of useful software
    # Welcome changing requirements, even late in development
    # Working software is delivered frequently
    # Close, daily co-operation between business people and developers
    # Face-to-face conversation is the best form of communication (co-location)
    # Projects are built around motivated individuals, who should be trusted
    # Self-organizing teams
    # Regular adaptation to changing circumstances

    # Agile methods break tasks into small increments with minimal planning, and do not directly involve long-term planning.
    # Iterations are short time frames (timeboxes) that typically last from one to four weeks. # Each iteration involves a team working through a full software development cycle including planning, requirements analysis, design, coding, unit testing, and acceptance testing when a working product is demonstrated to stakeholders.
    # Stakeholders produce documentation as required.

    # Team composition in an agile project is usually cross-functional and self-organizing without consideration for any existing corporate hierarchy or the corporate roles of team members.
    # Team members normally take responsibility for tasks that deliver the functionality an iteration requires.

    Scrum:
    # iterative, incremental methodology for project management often seen in agile software development
    # The main roles in Scrum are:
       1. the “ScrumMaster”, who maintains the processes (typically in lieu of a project manager)
       2. the “Product Owner”, who represents the stakeholders and the business
       3. the “Team”, a cross-functional group of about 5-9 people who do the actual analysis, design, implementation, testing, etc.

    # During each “sprint”, typically a two to four week period (with the length being decided by the team), the team creates a potentially shippable product increment (for example, working and tested software).

    # The set of features that go into a sprint come from the product “backlog”, which is a prioritized set of high level requirements of work to be done. Which backlog items go into the sprint is determined during the sprint planning meeting. During this meeting, the Product Owner informs the team of the items in the product backlog that he or she wants completed. The team then determines how much of this they can commit to complete during the next sprint, and records this in the sprint backlog.[4] During a sprint, no one is allowed to change the sprint backlog, which means that the requirements are frozen for that sprint. Development is timeboxed such that the sprint must end on time; if requirements are not completed for any reason they are left out and returned to the product backlog. After a sprint is completed, the team demonstrates how to use the software.

    # Represents a radically new approach for planning and managing software projects brings decision making authority to the level of operation properties and on certainties, scrum reduces defects , makes development process more efficient and reduces long term maintenance cost.[7]

        * What have you done since yesterday?
        * What are you planning to do today?
        * Do you have any problems that would prevent you from accomplishing your goal? (It is the role of the ScrumMaster to facilitate resolution of these impediments, although the resolution should occur outside the Daily Scrum itself to keep it under 15 minutes.)

    Thursday, November 20, 2014

    SQL: Play wid dates

    1. Get the system date-

    select GETDATE() as 'Today''sDate'

    Output-
    Today'sDate

    2014-11-21 00:11:16.593

    2. Extract YY, MM, DD, H/M/S from the date
    Year/Month/Day
    select Year(GETDATE()) as 'Year', Month(GETDATE()) as 'Month', Day(GETDATE()) as 'Day'
    Output
    Year Month Day
    2014 11 21

    H/M/S
    select DATEPART(HH, getdate()) as 'Hour', DATEPART(MM, getdate()) as 'Minute', DATEPART(S, GETDATE()) as 'Second'

    Output
    Hour Minute Second

    0 11 59

    3. DATEPART Function


    Syntax
    DATEPART(datepart,date)

    Commonly Used datepart


    datepartAbbreviation
    yearyy, yyyy
    monthmm, m
    dayofyeardy, y
    daydd, d
    weekwk, ww
    weekdaydw, w
    hourhh
    minutemi, n
    secondss, s

    4. DATEADD function
    Syntax
    DATEADD(datepart,number,date)
    e.g. Adding an year to current date
    Select DATEADD(YY, 1, getdate()) as 'NextYear'
    Output
    NextYear
    2015-11-21 00:32:33.570

    Selecting only date part using Convert function
    Select CONVERT(DATE, DATEADD(YY, 1, getdate())) as 'NextYear'
    Output
    NextYear

    2015-11-21

    5. DATEDIFF function
    Syntax
    DATEDIFF(datepart,startdate,enddate)

    e.g. Getting days difference between today and yesterday

    select DATEDIFF(DD, Getdate()-1, GetDate()) as 'Days between today & yesterday'
    Output
    Days between today & yesterday

    1

    6. Sample Problem- 
    Find all the employees who were hired in October 2003 from below data

    select empid, lastname, firstname, hiredate from HR.employees

    empid lastname firstname hiredate
    1 Davis Sara 2002-05-01 00:00:00.000
    2 Funk Don 2002-08-14 00:00:00.000
    3 Lew Judy 2002-04-01 00:00:00.000
    4 Peled Yael 2003-05-03 00:00:00.000
    5 Buck Sven 2003-10-17 00:00:00.000
    6 Suurs Paul 2003-10-17 00:00:00.000
    7 King Russell 2004-01-02 00:00:00.000
    8 Cameron Maria 2004-03-05 00:00:00.000

    select empid, lastname, firstname, hiredate from HR.Employees
     where DATEPART(YY, hiredate)=DATEPART(YY,DATEADD(YY, -11, getdate()))
     AND DATEPART(MM, hiredate)=DATEPART(MM, DATEADD(MM, -1, getdate()))

    Output
    empid lastname firstname  hiredate
    5 Buck Sven 2003-10-17 00:00:00.000

    6 Suurs Paul 2003-10-17 00:00:00.000

    Monday, October 6, 2014

    2014: Intw Que 2

    STRYKER

           What is a test plan document?
    test plan is a document detailing a systematic approach to testing a system such as a machine or software. The plan typically contains a detailed understanding of the eventual workflow.


                 What are the prerequisites for a test plan?
    The pre-requisite for a test plan are approved BRD (Business requirement) and SRS (Functional requirement) 

    Once approved BRD is available we will create a draft version of test plan and take Feature scope as an input from BRD in the test plan. 
    Once the SRS is created we will take applicable test types as an input which will go to test approach section of the test plan. we will also update the test plan for any changes to feature's scope, this may happen during SRS preparation where some of the business requirement may not be feasible to implement in the release

    A Project plan to define the Schedule, Roles & Responsibilities
    Organization's test strategy document are also require to define Test tools, defect management tools, Risk & Risk Management
                 What is the difference between test strategy and test approach
                What is the difference between web applications and client server application
               What is the difference between business logic and application server

               What are web services and how are they tested?

    Web Service is a method of communication between two electronic devices over a network.
    Web Services: What all do we need to test?
    •  Functionality: We need to look for the following in the midst of functional testing
      • Specification Review (SR)
      • Test Case Development (TCD)
      • Test Execution, examination of requests & responses
    • Performance: Testing web services performance may be complicated. To avoid this, following a simple rule of clearly mentioning the thresholds upfront, solves problems. Another key is to know the performance requirements in the most accurate manner.
    For e.g.
    • A good requirement: This service has been identified as serving 50,000 concurrent users with 10 second average response time
    • A bad requirement: This service should serve > 4000 concurrent users, and the response should be fast
    • Security: Web Services are wide-open in a network. This element opens up a host of vulnerabilities, such as penetration, Denial-of-Service (DOS) attacks, and great volumes of spam data, etc. Distinctive security policies have to be imposed at the network level to create a sound Service Oriented Architecture (SOA). There are certain security policies which are enforced during data transfer, and user tokens or certificates are common sights where data is protected with a password. Precise test cases aimed at directing these policies need to be designed to completely test the Web service security
    • Compliance: Compliance testing is required to ensure that: 
    • Web services meet certain specified standards
    • Authorize SOAP request/response messages
    • Authenticate WSDL definitions

    Difference between Test Plan and Test Stratgey
    Test Strategy: Usually describes the generic test approach an organization follows irrespective of any project. It's expected to be a one-time organization level document 
    Test Plan: Test Plan is more PROJECT specific. It keeps changing from project to project based on it's scope. & Test Strategy section which we include as part of Test Plan is the test approach we follow/define for that specific project. 

    How do you relate SDLC to STLC
    SDLC- SDLC is Software Development LifeCycle, it is a systematic approach to develop a software.

    STLC- The process of testing a software in a well planned and systematic way is known as software testing life cycle (STLC).


    S. No.PhaseSDLC - Software Development Life cycleSTLC - Software Test Life Cycle
    1Requirements GatheringRequirements gathering is done by business analyst. Development team analyze the requirements from the design, architecture & coding perspective.Testing team also review & analyze the requirements. Testing team identifies the testing requirements like what types of testing will be required and review the requirements for logical functional relationship between various features / modules, so that any gaps can be caught at an early stage.
    2DesignTechnical architect works for the high level & low design of the software. Business analyst works for the UI design of the applicationHere, test architect generally the test lead/manager, does the test planning, identify high level testing points. Basically, requirement detailing is done in this phase.
    3Coding or developmentDevelopment team does the actual coding based on the designed architecture.Testing team write the detailed test cases.
    4TestingIn SDLC, actual testing is carried out in this phase. It includes unit testing, integration testing & system testing etc..Test Execution and bug reporting, manual testing, automation testing is done, defects found are reported. Re-testing and regression testing is also done in this phase. But, I don't agree with this statement. So, if I want to relate the testing phase with STLC, I would say it it is testing of test cases & test plans i.e. is basically review of test cases, test scenarios etc.. Preparing test data and test automation
    5DeploymentApplication is deployed on production environment for real end users.Final testing and implementation is done is this phase and final test report is prepared. For this statement as well, I don't agree. For software / application deployment is basically, when it is installed for real use. So, this way, STLC, deployment would be when test when test cases getting used i.e. execution of test cases.
    6MaintenanceBasically, it includes, post production / deployment support & enhancements.Most of people say - Maintenance testing is carried out in this phase.My definition for this is - updation & maintenance of test plans, test case required for the testing of support requests & enhancements as a part of maintenance.

    Difference between software validation and verification 
     software validation ensures that the product actually meets the user's needs, and that the specifications were correct in the first place, Software validation ensures that "you built the right thing"
    software verification is ensuring that the product has been built according to the requirements and design specifications. Software verification ensures that "you built it right"

    Monday, September 22, 2014

    Quality Answers !!

    Tell me something about yourself
    (Starting Statement)
    I am having around 8.5 years of experience in Software quality assurance and testing.
    (What qualities I possess and Why I like testing)
    I am very passionate about the quality of the application and it's features I work for. Being a QA, testing not only helps to find out the defects/issues in the system but it also gives me an end-2-end idea of the overall system and helps me to understand business strategy. I try not to compromise on the quality of the product and services and this has been appreciated by some of world class clients for which I worked for like Microsoft, CVS Caremark.
    (Demonstrating my experience to work with client)

    Majority of my work experience is with few of fortune 500 organizations during which I directly worked with the client and have a good exposure to client interaction and to co-ordinate between offshore and onshore team.
    (A brief mentioning of what I know in terms of testing keywords)
    I have good hands on experience in software testing life cycle which includes analyzing requirements and participate in requirements review discussions, preparing and maintaining test artifacts, test execution, reporting and tracking defects, providing test status and sign-off
    Currently I am working as Test Lead with Galaxe Solutions India Pvt Ltd, thank you.

    What are your current role and responsibilities?
    Currently I am working as Test Lead and my responsibilities include
     - Understanding requirements and participating in requirement review discussion with BA
     - Dividing tasks among team member including myself
     - Maintaining query log for the queries related to requirements and get them addressed through BA
     - Preparing Test plan, test cases, reviewing TCs prepared by team members
     - Scheduling TCs walk through with client for his approval
     - Identifying TCs for automation and get them automated
     - Maintaining RTM, co-coordinating test execution
     - Reporting defects and verification of defect fixes
     - Reporting daily and weekly test status
     - Providing test sign off
    What is Quality
    Quality is a measure or standard of excellence of a product

    Why do you think Quality is important?

    Quality is very important aspect of any product or services being offered to end users. A good quality measure ensures that the product used by end users is what he is looking for and gives him confidence. e.g. there can be many products of similar nature but what matters most is that which one is the quality product. Good quality services also gives client confidence and helps to generate more business. Quality is important because this is something which helps to differentiate between a good and a great product

    Can you tell me some situations where you have demonstrated your passion about quality?
    1. In one of my project there was a feature where an order can be placed using CC. While ordering, a customer may choose to use the CC once or he has an option to save the CC for future use as well. All these details were submitted to another system through various web services. There was a defect in the system due to which if you use a CC as one time use it stores the CC information and then don't allow the same CC to be stored again. Since we didn't have access to DB of the 2nd system we raised this an issue, however our development team responded back saying that this is the design at their side and we can't fix it from our side. I discussed and explained this issue to my onsite client lead since it was a breach of privacy to store something user is not asking for. He then bring this issue with the other team and they agreed to get this fixed in their subsequent release.

    2. There was another situation where a feature was not working properly in consecutive builds. The fix for the defect in previous build was generating a new issue in the subsequent build. This was due to the reason that development team were not running the unit tests after making the fixes. I discussed this issue with my project manager who agreed to have the unit tests results available to QA team for the build. This process improvement helped a lot to not only QA team but to the development team as well since it was a bit time taking exercise to go back and forth for the defect.

    How will you know that the product or feature is ready to ship/release?
    Once we meet the test Exit Criteria for the product, product is good to ship/release

    What is Exit criteria?
    Exit criteria is set of specification or conditions which ensures that a product has passed the acceptable operational specifications. For example all the priority 1/2, severity 1/2 defects should be close to release the the product

    Who creates Exit criteria?
    Exit criteria is created based on the product requirements and organizational process, however this can vary on customer's need & expectations. Test exit criteria is prepared by QA team based on the discussion with QA Manager and customer.

    What is the first thing you should do once the Build is available for test?
    If there is an automated build system, we should review the BVT results of the build and examine if the build is good enough for the further testing or not. In case if there is no automated build system and BVT results  available, then QA team should run the BVT on build to make sure that if the build can be use for further tests

    What is BVT and who is responsible to run it?
    BVT is build verification test which includes basic test for the feature to ensure whether the build is good or not for further testing. Usually the build release team is responsible to run the BVT, however in certain scenarios where team is small or there is no build team, running BVT can be taken care by Dev or QA team itself.

    Why this company
    (What company do e.g. Stryker)
    1. Leading manufacturer of orthopedic products and medical specialties 
    2. It is one of the world’s leading medical technology companies and is dedicated to helping healthcare professionals perform their jobs more efficiently while enhancing patient care
    (Fact about company e.g. Stryker)
    1. historically increased revenues by 20% each year for the last 27 years
    2. Stryker is now at 323 on FORTUNE magazine’s list of top 500 U.S. companies in terms of revenue.
    3. Stryker corporation named 68 on FORTUNE Magazine’s “100 Best Companies to work for” list.

    Why do you want to leave your current Organization?
    I am doing good in my current organization, however 
    I feel that the current work has become a routine.
    OR
    I am not able to fully utilize my potential and capabilities

    I tried to explore other opportunities in my current orgranization but Since my current organization is small so there are limited opportunities hence I am looking forward for this opportunity which will help me for growth and advancement in my career

    Where do you see yourself after X years?

    I would like to learn and gain knowledge about the product & domain I will be working for. This will be helping me to become an expert in the respective field and achieve a position where I can contribute towards the growth of the organization
    Why should we hire you?