0% found this document useful (0 votes)
69 views142 pages

Software Testing and Quality Assurance Chapter 03 Code Quality 1

Uploaded by

Mo Sa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views142 pages

Software Testing and Quality Assurance Chapter 03 Code Quality 1

Uploaded by

Mo Sa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 142

Software Testing and Quality Assurance

Review and Code Quality


AHMED A. QAZZAZ OCT 2021























Index
• Code Review
• Code Quality
• Code Quality Factors
• Coding Standards
• Refactoring
• Automatic Analysis

AHMED A. QAZZAZ OCT 2021





















Software Review
Software Review
• Software review is the second task in the software testing life cycle
• Its an activity mean to review/test the work and examined for feedback
• Review team helps in finding defects soon, to reduce the cost of fixing things in later stages.
• Review can be applied on all parts of the software
• Code
• Documents
• Producers
• Data

AHMED A. QAZZAZ SEP 2021


Software Review
SOFTWARE REVIEW

STATIC TESTING DYNAMIC TESTING

FORMAL FUNCTIONAL TESTING

INFORMAL NON-FUNCTIONAL

AHMED A. QAZZAZ SEP 2021

























Dynamic Testing (Testing)
• Dynamic execution for the software code, can be applied on code only to find defects/ bugs in
the application.
• Can not be applied on other software parts rather than code.

AHMED A. QAZZAZ SEP 2021

























Static Testing (Review)
• Code will not be executed in this type, it will be manually checked, line by line and evaluated.
• Also it will be a full review for all kind of documents in the software development cycle.
• Its important to find issues in the document, data and producers to avoid fixing error and
defect in the delivered application in later stages.

AHMED A. QAZZAZ SEP 2021
























Informal Review
• Review is a written or verbal review requested by a developer of a work product to improve
that product
• Desk Check
• Peer Review

AHMED A. QAZZAZ SEP 2021
























Desk Check
• Is an informal review where the author distributes a work product to peers for reviews and
comments.
• A desk check is the first line of defense against defects. You can speed up formal inspections by
taking care of simple defects in desk checks first.
• For many work products, desk checks suffice, and you might not need to go to a formal
inspection.

AHMED A. QAZZAZ SEP 2021













Peer Review
• is directed at reviewing short documents, chapters or parts of a report, a coded printout of a
software module, and the like.
• Peer reviews can take several forms and use many methods; usually, the reviewers are all peers,
not superiors, who provide professional assistance to colleagues.
• The main objective of inspections and walkthroughs is to detect as many design and
programming faults as possible.

AHMED A. QAZZAZ SEP 2021















Formal Review
• Review is a written review conducted by a team leader or a moderator for the purpose of
identifying, documenting, and fixing defects in a work product

• Formal Inspection
• Expert Opinion
• Audits

AHMED A. QAZZAZ SEP 2021












Formal Inspection
• An inspection is a formal review meeting where participants identify and document defects or
possible improvements in a work product
• Team may contain Moderator, Programmer, designer, QA Specialist.
• Some steps for a formal Inspections on: Preparation – Overview - Page-by-page Review -
Rework - Follow-up – Approval

AHMED A. QAZZAZ SEP 2021

















Expert Opinion
• prepared by outside experts, support quality evaluation by introducing additional abilities to
the internal review staff.
• Outside experts transmit their expertise by either:
• Preparing an expert’s judgment about a document or a code section.
• Participating as a member of an internal formal inspection team.

AHMED A. QAZZAZ SEP 2021













Software Audits
• Is a type of software review in which one or more auditors who are not members of the software
development organization conduct "An independent examination of a software product,
software process, or set of software processes to assess compliance with specifications,
standards, contractual agreements, or other criteria.
• Software audit is a Certification, or third-party assessment (referred to as registration in some
countries), is carried out by an independent organization against a particular standard.

AHMED A. QAZZAZ SEP 2021
















I C
Requirements Review E X T RA T OP
Requirements Review
• Requirements is a difficult  process. An expected effect of complex work is the possibility of
introducing errors along the way.  This is where the requirements review process comes in.
• A requirements review is a meeting where you gather all of your stakeholders together and
walk-through the requirements documentation, page-by-page, line-by-line, to ensure that the
document represents everyone’s complete understanding of what is to be accomplished in this
particular software.
• If software testing depends on good requirements, it is important to understand some of the
key elements of quality requirements

AHMED A. QAZZAZ SEP 2021





Requirements Review
• Verifiable
• Clear
• Complete
• Consistent
• Traceable
• Feasible
• Necessary
• Implementation Free

AHMED A. QAZZAZ SEP 2021

























Verifiable
• Can be measured and tested
• The UI should be user friendly
• The user interface shall be menu driven. It shall provide dialog boxes, help screens, radio
buttons, dropdown list boxes, and spin buttons for user inputs.

• The product should work well


• The output of the program shall usually be given within 10 s.

AHMED A. QAZZAZ SEP 2021















Clear
• Requirements should be Simple sentences will most often suffice for a good requirement. 
• Should be no more than 30-50 words in length
• Must be easily read and understood by non technical people.
• Must be unambiguous and not subject to multiple interpretations.

AHMED A. QAZZAZ SEP 2021













Clear
• The system shall be implemented using ASP.
• The system shall be implemented using Active Server Pages (ASP).
• Job poster enters job posting details and reviews them before saving.
• There are three requirements in that statement: There’s a requirement for entering the job
posting details. There’s a requirement for reviewing them. And there’s a requirement for saving
them.
• This requirement should be written in three requirements.

AHMED A. QAZZAZ SEP 2021








Complete
• All needed information about the requirement should be found.
• There should be no possibility for guessing.
• If the requirement represents a number or a quantity, a measurement unit should be defined

AHMED A. QAZZAZ SEP 2021



















Example
• Professor user should login the system using username, password, and any other relative
information

• Professor user should login the system using username, password, and department code.

• The system should be integrated with a payment getaway


• System should be integrated with PayPal

AHMED A. QAZZAZ SEP 2021


Consistant
• Does not conflict with other requirements
• Use the same terminology through all requirements
• Does not duplicate other requirements

AHMED A. QAZZAZ SEP 2021























Example
• Application should always start on home screen
• Users cannot use the application unless they login

• Conflict between these two requirements because the first one must start on home screen and
the second one tells that it should start on login screen

AHMED A. QAZZAZ SEP 2021
























Traceable
• Requirements should have a unique identifier
• Requirement cannot be broken into smaller requirements
• Can be easily traced through design implementation and testing phase

AHMED A. QAZZAZ SEP 2021





















Example
• Student information should be presented in details screen
• UR 4.1 | Student information should be presented in details screen

AHMED A. QAZZAZ SEP 2021

























Feasible
• Must meet the exiting technology
• Can be achieved within the budget
• Can be achieved within the schedule
• Will be used by end-users

AHMED A. QAZZAZ SEP 2021
























Code Quality
Code Quality
• Code Quality refers to the usefulness and maintainability of code in long term
• Code Quality can have a major impact on the software quality.
• To achieve high quality code there are several methods
• Code Review
• Coding Standards
• Refactoring
• Analysis
• Testing

AHMED A. QAZZAZ OCT 2021






Code Review
• Manual code reviews are important for verifying the intent of the code.
• When code reviews are done well, they improve overall software quality

AHMED A. QAZZAZ OCT 2021

























Coding Standards
• A coding standard makes sure everyone uses the right style. It improves consistency and
readability of the codebase.
• This is key for lower complexity and higher quality
• Examples
• No more than one statement per line.
• Line length should not exceed 80 or 100 characters.
• More standards in Java https://ace.apache.org/docs/coding-standards.html * read only

AHMED A. QAZZAZ OCT 2021













Refactoring
• One way to improve the quality of an existing code is through refactoring.
• Refactoring  code can help you clean up your code and lower its complexity.

AHMED A. QAZZAZ OCT 2021

























Code Analysis
• The best way to improve quality is by analyzing code automatically.
• By running a static analyzer over code early and often, you’ll make sure the code that gets to
the code review phase is the highest quality possible.

AHMED A. QAZZAZ OCT 2021

























Testing
• Testing has been considered as having a key role in building high quality code, and therefore it
has been widely used in practice.

AHMED A. QAZZAZ OCT 2021

























Code Quality Factors
Code Quality Factors
• Efficiency
• Reliability
• Robustness
• Portable
• Maintainability
• Readability

AHMED A. QAZZAZ OCT 2021























Efficiency
• The efficiency of the code is directly related to the performance and speed of the software,
whereby the quality can be evaluated on its basis.

AHMED A. QAZZAZ OCT 2021

























Reliability
• It refers to the ability of the software code to perform consistent and failure-free operations
every time it runs.

AHMED A. QAZZAZ OCT 2021

























Robustness
• The robustness of the code is its ability to deal with the errors while the program is being
executed, even under unusual conditions.

AHMED A. QAZZAZ OCT 2021

























Portability
• This is the ability of the code to be able to run on as many machines and operating systems as
possible

AHMED A. QAZZAZ OCT 2021

























Maintainability
• This refers to the addition of new features, modification in the existing ones or fixing the bugs
with minimum efforts.

AHMED A. QAZZAZ OCT 2021

























Readability
• The code should be readable in a way that it should be easily understood by any new person
reading it or someone who has not seen it in a while

AHMED A. QAZZAZ OCT 2021

























Code Review
• In code review (also called static unit testing) a programmer does not execute the unit; instead,
the code is examined over all possible behaviors that might arise during run time

• The goal of such an exercise is to assess the quality of the software in question, not the quality
of the process used to develop the software which done in software review

• The objective of code review is to review the code, not to evaluate the author of the code. A
clash may occur between the author of the code and the reviewers, and this may make the
reviews unproductive.

AHMED A. QAZZAZ OCT 2021























Code Reviewer
• Reviewer checking:
• if the code is easy to understand
• Can be tested
• Contains Duplicated Code
• Contains Too Big Code
• Follow the Standards and Guidelines

AHMED A. QAZZAZ OCT 2021




















Objectives of Code Review
• To achieve better code quality
• Finding Faults
• Knowledge transfer
• Increase the sense of mutual responsibility
• Finding better solutions

AHMED A. QAZZAZ OCT 2021

















Code Review Process
REVIEW COMPLETE

CODE DONE REQUEST REVIEW ACCEPT REVIEW WRITING COMMENTS

SUBMIT FORM TO
DEVELOPMENT TEAM

AHMED A. QAZZAZ OCT 2021

























Code Review - Techniques
• Over the shoulder
• Email Pass-Around
• Pair Programming

AHMED A. QAZZAZ OCT 2021

























Code Review
Over-the-shoulder Review
- Techniques

• An experienced team member walks through the new code, providing suggestions through a
conversation.
• It is the easiest approach to code reviews and does not require a pre-defined structure
• Such a code review may still be done informally today, along with a formal code review
process that may be in place

AHMED A. QAZZAZ OCT 2021




Code Review
Email Pass-Around
- Techniques

• Same as the on-the-shoulder technique but with geographically distributed teams. 


• Sending emails to whole development team with changes and differences

AHMED A. QAZZAZ OCT 2021


















Code Review
Pair Programming
- Techniques

• Pair programming is a continuous code review process. Two developers sit at a workstation,
but only one of them actively codes whereas the other provides real-time feedback

AHMED A. QAZZAZ OCT 2021

























Code Review - Tools
• There is a group of software tools can assist in code review process.
• Mainly Source Control / Git protocol used for code reviews.

AHMED A. QAZZAZ OCT 2021

























Review Board
• is a web-based, open source tool for code review. To test this code review tool

w.reviewboard.org
o.reviewboard.org/r/
AHMED A. QAZZAZ OCT 2021























GitHub
• maintain your Git repositories on the cloud, you may have already used forks and pull requests
to review code

m/features/code-review/
AHMED A. QAZZAZ OCT 2021























Other Tools
Review Boar Visual Exper

Crucibl Gerri

GitHu Rhodecod

Phabricato Veracod

Collaborato Reviewabl

CodeScene Peer Review for Trac


AHMED A. QAZZAZ OCT 2021
t























EXAMPLES

AHMED A. QAZZAZ OCT 2021

























Reviewers Nots
• Review writes a comment about variable names

Review comments about the iterations count

AHMED A. QAZZAZ OCT 2021

























Reviewer notes

Review comments about the return type of the function

AHMED A. QAZZAZ OCT 2021

























Code Review - Check for faults
• using , with null text will cause a NullPointerException which is a FAULT
• but using it with empty string will cause a failure.

AHMED A. QAZZAZ OCT 2021


























Code Review - Check for faults
• Logical faults: is a bug in a program that causes it to operate incorrectly

Division process will truncate the fraction since both inputs are integers

AHMED A. QAZZAZ OCT 2021

























Code Review - Logical Faults
• Logical faults: is a bug in a program that causes it to operate incorrectly

Null Pointer In nite Loop

te Recursion
AHMED A. QAZZAZ OCT 2021
fi
fi























Code Review - GUI faults
• GUI Fault is used to identify the presence of defects is a software under test by using Graphical
user interface (GUI).

AHMED A. QAZZAZ OCT 2021

























Code Review - GUI faults
• Inappropriate Button size
• No Micro-interactions
• Color Contrast
• Typographical Hierarchy
• White Space or Negative Space
• Faulty Alignment and Grouping

AHMED A. QAZZAZ OCT 2021





















Code Review - Security Faults
• Is a type Testing that uncovers vulnerabilities, threats, risks in a software application and
prevents malicious attacks from intruders.

AHMED A. QAZZAZ OCT 2021

























Code Review - Check for Performance
• a computer program may be optimized so that it executes more rapidly, or to make it capable of
operating with less memory storage or other resources, or draw less power.

AHMED A. QAZZAZ OCT 2021

























Using ‘+’ sign against builder class

AHMED A. QAZZAZ OCT 2021

























Using ‘+’ sign against builder class

AHMED A. QAZZAZ OCT 2021

























Performance tips
• There are several source of performance tips and hints on both iOS and Android development
using both Java, and Kotlen.
• tips for Android development: https://developer.android.com/training/articles/perf-tips
• tips for iOS development: https://www.raywenderlich.com/2752-25-ios-app-performance-tips-
tricks

AHMED A. QAZZAZ OCT 2021









Performance Tools
• There are several tools can be used to profiling iOS and Android apps.
• Tools for Android profiling: https://developer.android.com/studio/profile/android-profiler
• Tools for iOS profiling: Xcode instruments (https://www.appcoda.com/xcode-instrument/)

AHMED A. QAZZAZ OCT 2021



















Code Quality - Method


• Code Review
• Standereds
• Refactoring
• Code Analyzing
• Testing

AHMED A. QAZZAZ OCT 2021























Standards
• Standards aim to generate more consistent code on collaborative projects.
• Easier to understand
• Easier to develop
• Easier to maintain
• Reduce over all cost

AHMED A. QAZZAZ OCT 2021








Official Standards Sources
• Swift standards: https://engineering.vokal.io/iOS/CodingStandards/Swift.md.html
https://swift.org/documentation/
• Kotlin standards: https://kotlinlang.org/docs/reference/coding-conventions.html
• Java standards examples: https://android.jlelse.eu/java-coding-standards-ee1687a82ec2

AHMED A. QAZZAZ OCT 2021























Code Standards
Examples

• 1- Limit usage of global variables, and statics.


• Global scope, and static variables are memory resident variables, so the memory location will
always be busy, even if the variable will no longer needed in the app life cycle

• Solutions
• Passing variables around
• Store/Load locally

AHMED A. QAZZAZ OCT 2021






Code Standards
Examples

• 2- Headers for modules


• Writing the header for each module will not make the code looks neat only, it will provide
valuable information about the module.
• Name of the module
• Date of module creation
• Author of the module
• Modification history

AHMED A. QAZZAZ OCT 2021



















Code Standards
Examples

• 3- Never use identifier for multiple purposes


• Each variable should be given a descriptive and meaningful name indicating the reason behind
using it. This is not possible if an identifier is used for multiple purposes and thus it can lead
to confusion to the reader.

AHMED A. QAZZAZ OCT 2021




















Code Standards
Examples

• 4- Well documented code


• The code should be properly commented for understanding easily. Comments regarding the
statements increase the understandability of the code

AHMED A. QAZZAZ OCT 2021

























Code Standards
Examples

• 5- Exceptions rather than errors


• Functions should not return a constant value as error (e.g. 0 for failure , 1 for success),
functions should throws exception when it fails to achieve its task.

AHMED A. QAZZAZ OCT 2021























Code Style
• Code style refers to how a script formatted and written, it does not affect the functionality of
the code but it has a large impact on readability
• Indentation
• Parameter listing
• Naming
• Comments
• Coercions and Castings

AHMED A. QAZZAZ OCT 2021














Code Style
Examples (Swift)
Both of the following code will set a string in the variable pageLableText with the same
value

Incorrect code style

Correct code style

AHMED A. QAZZAZ OCT 2021

























Code Style
Examples (Swift)

Incorrect code style

Correct code style

AHMED A. QAZZAZ OCT 2021

























Code Style
Examples (swift)

Incorrect code style

Correct code style

AHMED A. QAZZAZ OCT 2021

























Code Style
Examples (Java)

Incorrect code style

Correct code style

AHMED A. QAZZAZ OCT 2021

























Code Style
Examples (Java)

Incorrect code style

Correct code style

AHMED A. QAZZAZ OCT 2021

























Code Quality - Method
• Code Review
• Standereds
• Refactoring
• Code Analyzing
• Testing

AHMED A. QAZZAZ OCT 2021























Refactoring
• Is a technique of changing the code (to improve readability) without changing the code
functionality.
• Refactoring can be applied on code to make it match the standards.
• for example renaming a variable or class over the whole code.

AHMED A. QAZZAZ OCT 2021









Refactoring Examples
• Code on the left show a class for data model named Product with its constructor.
• but parameter n in the constructor might not be the best naming for this parameter

AHMED A. QAZZAZ OCT 2021

























Refactoring Techniques
EXTRACTION MOVING RE ORGANIZING GENERALIZATION

• Extract Method • Move Methods • Hide Delegates • Pull Up


• Extract Class • Inline Classes • Introduce • Push Down
Parameter Object
• Extract SubClass • Move Fields
• Replace Magic
• Remove Middle Man Numbers

SIMPLIFYING

• Rename • Passing Objects

• Replace • Replace Errors with Exceptions


Parameters
AHMED A. QAZZAZ OCT 2021






















Extract Method Example

AHMED A. QAZZAZ OCT 2021

























Simple Example
• This class or struct contains a
large number of instance
variables.
• These variables can be grouped
in other classes and be used in
this main class

AHMED A. QAZZAZ OCT 2021

























Extract Subclasses

AHMED A. QAZZAZ OCT 2021

























Code Smells
BLOATERS OOP ABUSE CHANGE PREVENTERS DISPENSABLES

• Long Methods • Identical classes - • Divergent Change • Comments


different names
• Large Classes • Shotgun Surgery • Duplicated Code
• Switch Statement
• Long Parameters • Parallel Inheritance • Data Class
List • Refused Bequest Hierarchies
• Dead Code
• Primitive Obsession • Temporary Field
• Lazy Class
COUPLERS
• Speculative Generality

• Feature Envy • Middle Man • Inappropriate


relationship
• Message Chains • Incomplete Library Class

AHMED A. QAZZAZ OCT 2021






















Bloaters
https://refactoring.guru/refactoring/smells/bloaters
Bloaters

Long Method
• Any method that is larger than 10 lines, or needs a scroll down
• The best treatment for this case, is to extract method
• if you need to write a comment about something inside the method
You should take this part to a sub method

• Check this example: https://makolyte.com/refactoring-the-long-method-code-smell/

AHMED A. QAZZAZ OCT 2021





















AHMED A. QAZZAZ OCT 2021























AHMED A. QAZZAZ OCT 2021























Final Results

AHMED A. QAZZAZ OCT 2021

























Bloaters

Large Class
• Class that contains tons for lines of code, that is over the
screen hight
• The best treatment for this case, is to
• Extract class
• Extract sub classes
• Extract interfaces

• Check this example: https://makolyte.com/refactoring-the-large-class-code-smell/

AHMED A. QAZZAZ OCT 2021


















Large Class Example
• This class is 200 lines long

Final Results

AHMED A. QAZZAZ OCT 2021

























Bloaters

Long Parameters List


• Use more than three parameters to the function
• The best treatment for this case, is to
• Replace Parameters with functions calls
• Passing Objects
• Introduce Parameter Object

AHMED A. QAZZAZ OCT 2021
















Replace Parameters with Function call

AHMED A. QAZZAZ OCT 2021

























Passing Object
Preserve whole Object

AHMED A. QAZZAZ OCT 2021

























Introduce Parameter Object

AHMED A. QAZZAZ OCT 2021

























OOP Abusers
https://refactoring.guru/refactoring/smells/oo-abusers
OOP Abuse

Switch Statement
• Using a complex switch operator, or a sequence of if statements
• When you see switch, you should think of polymorphism
• There are several refactoring methods to treat the switch problem
• Sub Classes
• State/Strategy Design Pattern

AHMED A. QAZZAZ OCT 2021









Use State / Strategy DP

AHMED A. QAZZAZ OCT 2021

























AHMED A. QAZZAZ OCT 2021























OOP Abuse

Temporary Fields
• Fields in class that is not getting values all the time.
• The best treatment for this case, is to
• Extract class

AHMED A. QAZZAZ OCT 2021






















OOP Abuse

Refused Bequest
• Subclass that uses only some of the parent class methods and fields
• The best treatment for this case, is to
• Extract Subclasses

• Sub class that refuse the parent implementation of methods


• Push Down Methods

AHMED A. QAZZAZ OCT 2021











Push Down Method

AHMED A. QAZZAZ OCT 2021

























Change Preventers
https://refactoring.guru/refactoring/smells/change-preventers
Change Preventers

Divergent Change
• You need to change unrelated methods inside the class when you make
a different change
• for example, adding new product type, will make us change the search, display, and sorting
methods.
• The best treatment for this case, is to
• Extract classes
• Extract subclasses

AHMED A. QAZZAZ OCT 2021

















AHMED A. QAZZAZ OCT 2021























Change Preventers

Shotgun Surgery
• Making a change will force us to make many small changes on
other classes
• The best treatment for this case, is to
• Move Methods
• Move Fields
• Inline Classes

AHMED A. QAZZAZ OCT 2021


















AHMED A. QAZZAZ OCT 2021























Change Preventers

Parallel Inheritance
Hierarchies

• Whenever you create a subclass for a class, you find yourself


needing to create a subclass for another class.
• The best treatment for this case, is to
• Move Methods
• Move Fields

• check this article: https://dzone.com/articles/code-smell-series-parallel-inheritance-hierchies

AHMED A. QAZZAZ OCT 2021
















Dispensables
https://refactoring.guru/refactoring/smells/dispensables
Dispensables

Lazy Class
• The class that is ridiculously small.
• for example class that holds one attribute
• Inline Class
• Collapse Structure

AHMED A. QAZZAZ OCT 2021
















Dispensables

Duplicated Code
• Two code fragments doing the same function
• The best treatment for this case, is to
• Extract Methods
• Pull Up Methods
• Extract Subclasses
• …

AHMED A. QAZZAZ OCT 2021


















Dispensables

Dead Code
• Code that is no longer used
• Remove These code segments

AHMED A. QAZZAZ OCT 2021

























Couplers
https://refactoring.guru/refactoring/smells/couplers
Couplers

Feature Envy
• When a method in a class keep using an instance of another class,
it will be better to move it to the other class
• The best treatment for this case, is to Move Method
• if you need to write a comment about something inside the method
You should take this part to a sub method

AHMED A. QAZZAZ OCT 2021
























Feature Envy

AHMED A. QAZZAZ OCT 2021

























Couplers

Messages Chain
• A message chain occurs when a client requests another object,
that object requests yet another one, and so on
• The best treatment for this case, is to
• Hide Delegates
• Extract Methods
• Move Methods

AHMED A. QAZZAZ OCT 2021

















Couplers

Middle Man
• If a class performs only one action, delegating work to another class
• The best treatment for this case, is to
• Remove Middle Man Class

AHMED A. QAZZAZ OCT 2021

















Other Smells
Other Smells

Magic Numbers
• When you use a constant number directly in the code, you should use symbolic (constant)
instead.
• What is applied for numbers can be applied for strings too

AHMED A. QAZZAZ OCT 2021

























Example (Numbers)

Bad smell

Refactoring

AHMED A. QAZZAZ OCT 2021

























Example (String)

Bad smell

Refactoring

AHMED A. QAZZAZ OCT 2021

























Other Smells

Errors over exceptions


• When you write a method that might fail you should
• not show error values, you should throw exceptions
• make the caller handle these exceptions

AHMED A. QAZZAZ OCT 2021

























Example

Refactoring

Bad smell

AHMED A. QAZZAZ OCT 2021

























Code Quality - Method
• Code Review
• Standereds
• Refactoring
• Code Analyzing
• Testing

AHMED A. QAZZAZ OCT 2021























Code Analyzing
• software checks source code for compliance with a predefined set of rules or best practices
• The use of analytical methods to inspect and review source code to detect bugs has been a
standard development practice

AHMED A. QAZZAZ OCT 2021

























Code Analyzing
• Following are the types of defects found by the tools during static analysis:
• A variable with an undefined value
• Inconsistent interface between modules and components
• Variables that are declared but never used
• Unreachable code (or) Dead Code
• Programming standards violations
• Security vulnerabilities
• Syntax violations

AHMED A. QAZZAZ OCT 2021










Code Analyzing
• Compiler Warnings and Errors
• Possibly uninitialized Variable
• Undocumented empty block
• Assignment has no effect
• Checkstyle
• Check for code guideline violations
• http://checkstyle.sourceforge.net
• FindBugs
• Check for code anomalies
• http://findbugs.sourceforge.net

AHMED A. QAZZAZ OCT 2021




















Setup and Usage

https://medium.com/fantageek/how-to-setup-android-projects-8c306aaeb519

https://medium.com/developerinsider/how-to-use-swiftlint-with-xcode-to-enforce-swift-style-
and-conventions-368e49e910

AHMED A. QAZZAZ OCT 2021

























AHMED A. QAZZAZ OCT 2021























Check Style
• Checkstyle: A static analysis tool that focuses on Java coding style and standards.
• whitespace and indentation
• variable names
• Javadoc commenting
• code complexity
• number of statements per method
• levels of nested ifs/loops
• lines, methods, fields, etc. per class
• proper usage
• import statements
• regular expressions
• exceptions
• I/O
• thread usage, ...

AHMED A. QAZZAZ OCT 2021









SpotBug
• SpotBug: Java static analysis tool that focuses on Faults usage errors in code such as:
• null pointers
• useless/dead code
• unclosed I/O streams
• infinite loops
• infinite recursion
• Missing initialization
• Incorrect branching condition
• Missing test for null

AHMED A. QAZZAZ OCT 2021






Refectory
• Refactoring is a disciplined technique for improving the structure of existing code without
changing the observable behaviours

AHMED A. QAZZAZ OCT 2021

























Code Quality - Method
• Code Review
• Standereds
• Refactoring
• Code Analyzing
• Testing

AHMED A. QAZZAZ OCT 2021























Testing
• Testing process will pass several phases, and it has its own documents.
• Test design is process to describe how test should be done.
• In the next chapter we will focus more on Testing

AHMED A. QAZZAZ OCT 2021






















Dynamic Testing Types
• White Box testing
• Black Box testing

AHMED A. QAZZAZ OCT 2021

























Test Cases and Test Scenarios
• You need to derive cases from your app for each functionality, and document these cases in standard
format
• for example, login service with username and email from mobile side perspective :
• {valid email, valid password}
• {invalid email, valid password}
• {valid email, invalid password}
• {invalid email, invalid password}
• {empty email, empty password}
• ….

AHMED A. QAZZAZ OCT 2021

You might also like