UNIT5
UNIT5
1. Select data structures that will meet the need of the design.
2. Keep conditional logic as simple as possible.
3. Understand the software architecture and make interfaces that
are according to it.
4. Select meaningful variable names and follow other local coding
standards.
5. Write code that's self-documenting.
6. Create a visual layout.
7. Constrain your algorithm by structured programming practice.
Programming Practices
• Control construct
The single entry and exit constructs need to be used.
• Use of goto
The goto statements make the program unstructured. So avoid use
of goto statements as possible.
• Information hiding
• Nesting
Structure inside another structure is called as nesting. If there is too
deep nesting then it becomes hard to understand the code as well as
complex.
• User defined data types
User can define data type to enhance the readability of the code.
Image source : Google
Programming Practices (Contd.)
• Modular size
The size of program may be large or small. There is no rule for size of the
program. So as possible generate different module but not of large size.
• Side effects
Sometimes if some part of code may change then it may generate some
kind of problems called as side effects.
• Robustness
If any kind of exception is generated, the program should generate some
kind of output. Then it is called as robustness. In this situation the
programs do not crash.
• Switch case with defaults
Inside the switch case statement if any value which is unpredictable is
given as argument then there should be default case to execute it
Coding Standards
Types of
Reviews
▪ A few members of the development team are given the code few days before
the walk through meeting to read and understand code.
▪ Each member selects some test cases and simulates execution of the code by
hand
▪ The members note down their findings to discuss these in a walk through
meeting where the coder of the module is present.
Code Inspection
▪ The aim of Code Inspection is to discover some common types of
errors caused due to improper programming.
▪ In other words, during Code Inspection the code is examined for the presence
of certain kinds of errors.
• For instance, consider the classical error of writing a procedure that
modifies a parameter while the calling routine calls that procedure with a
constant actual parameter.
• It is more likely that such an error will be discovered by looking for these
kinds of mistakes in the code.
▪ In addition, commitment to coding standards
Few Classical Programming Errors
Don’t view testing as a “safety net” that will catch all errors that occurred
because of weak software engineering practice.
Who tests the Software?
Developer
Tester
Understands the system but, will test Must learn about the system,
"gently" but, will attempt to break it and,
and, is driven by "delivery" is driven by quality
Verification
Are we building the product right?
The objective of Verification is to make sure that the product being develop is as
per the requirements and design specifications.
Validation
Are we building the right product?
The objective of Validation is to make sure that the product actually meet up the
user’s requirements, and check whether the specifications were correct in the
first place.
Verification vs Validation (Contd.)
Process of evaluating products of a Process of evaluating software at the end
development phase to find out whether of the development to determine whether
they meet the specified requirements. software meets the customer expectations
and requirements.
Activities involved: Reviews, Meetings and
Inspections Activities involved: Testing like black box
testing, white box testing, gray box testing
Carried out by QA team
Carried out by testing team
Execution of code is not comes under
Verification Execution of code is comes under
Validation
Explains whether the outputs are
according to inputs or not Describes whether the software is
accepted by the user or not
Software Testing Strategy
Unit Testing
• It concentrate on each unit of the software as
implemented in source code.
• It focuses on each component individual,
ensuring that it functions properly as a unit.
Integration Testing
• It focus is on design and construction of
• software architecture
• Integration testing is the process of testing the
interface between two software units or modules
Software Testing Strategy (Contd.)
Validation Testing
• Software is validated against requirements
established as a part of requirement modeling
• It give assurance that software meets all
informational, functional, behavioral and
performance requirements.
System Testing
• The software and other software elements
are
tested as a whole
• Software once validated, must be combined with
other system elements e.g. hardware, people,
database etc…
Unit Testing
• Unit is the smallest part of a software system that is testable.
• It may include code files, classes and methods which can be tested
individually for correctness.
• Unit Testing validates small building block of a complex system before
testing an integrated large module or whole system
• The unit test focuses on the internal processing logic and data
structures within the boundaries of a component.
Unit Testing (Contd.)
▪ The module is tested to ensure that information properly flows into
and out of the program unit
▪ Local data structures are examined to ensure that data stored
temporarily maintains its integrity during execution
▪ All independent paths through the control structures are exercised to
ensure that all statements in module have been executed at least
once
▪ Boundary conditions are tested to ensure that the module operates
properly at boundaries established to limit or restricted processing
▪ All error handling paths are tested.
Unit Testing (Contd.)
▪ Component-testing (Unit Testing) may be done in isolation from rest
of the system
▪ In such case the missing software is replaced by Stubs and Drivers and
simulate the interface between the software components in a simple
manner
Unit Testing (Contd.)
▪ Let’s take an example to understand it in a better way.
▪ Suppose there is an application consisting of three modules
say, module A, module B & module C.
▪ Developer has design in such a way that module B depends
on module A & module C depends on module B
▪ The developer has developed the module B and now wanted
to test it.
▪ But the module A and module C has not been
developed yet.
▪ Driver and/or Stub software must be developed for each unit test
▪ A driver is nothing more than a "main program"
• It accepts test case data
• Passes such data to the component and
• Prints relevant results.
▪ Driver
• Used in Bottom up approach
• Lowest modules are tested first.
• Stimulates the higher level of components
• Dummy program for Higher level component
Unit Testing (Contd.)
▪ Stubs serve to replace modules that are subordinate (called by) the component
to be tested.
▪ A stub or "dummy subprogram"
• Uses the subordinate module's interface
• May do minimal data manipulation
• Prints verification of entry and
• Returns control to the module undergoing testing
▪ Stubs
• Used in Top down approach
• Top most module is tested first
• Stimulates the lower level of components
• Dummy program of lower level components
Metrics
• Metrics are quantitative measure that the software engineer to gain the
efficiency of the process
Types of
Measures
Size Complexity
Measure Measure
Size Measure
Size oriented measure is derived by considering the size of software that has been
produced.
Any organization builds a simple record of size measure for the software projects. It is
built based on past experiences.
Set of size measure is given below:
• Halstead's theory of software science is one of "the best known and most
thoroughly studied composite measures of (software) complexity".
• Software science assigns quantitative laws to the development of computer
software, using a set of primitive measures that may be derived after code is
generated or estimated once design is complete.
Halstead Measure (Contd.)
• These follow:
• n1= the number of distinct operators that appear in a program. n2= the
number of distinct operands that appear in a program. N1= the total number
of operator occurrences. N2= the total number of operand occurrences.
Formula
Symbol
Program Length N N = N1 + N2
n = n1 + n2
Program Vocabulary n
Volume V V = N * (log2n)
Difficulty D D = (n1/2) * (n2/2)
Effort E E=D*V
Halstead Measure (Contd.)
• Program Length
The length of a program is total usage of operators and operands in the program.
Length = N1 + N2
• Program vocabulary
The program vocabulary is the number of unique operators and operands used in the program.
Vocabulary n = n1 + n2
• Program Volume
The program volume can be defined as the maximum number of bits to encode the program.
V=Nlog2n
N= n1log2n1+ n2log2n2
Knot Count
• Knot is a crossing of control flows. These crossings occur due to
non-structural
• jumps in the program.
• Typically the goto statements cause this kind of non-structural jump. This
metric is designed for FORTRAN language.
• If the knot is more intertwined then that means the program is more
complex.
• The code with large knots is generally extremely difficult to read and
understand.
• The example is shown on the right side.
Comparison of Different Metrics
Size measure Cyclomatic Complexity Halstead’s Knot count
measure
∙ This is simple ∙ This measure is based ∙ The ∙ It is basically
method of on the control flow of measurable designed for
obtaining the the programming quantities of the FORTRAN
metrics. It is constructs such as if the program programs.
based on lines then else, do-while, are operators
of code. repeat-until and so and operands.
on.
∙ Modules of the ∙ For larger number of ∙ It is based on ∙ More number
same size can decisions larger is the length and of knots
have different complexity. volume of the indicates more
complexities. program. complex in
the
program.
www.paruluniversity.ac.in