Pmse Module III
Pmse Module III
The variable names should be in camel case All the names of constants should be in
letters starting with a lower case letter. For upper case. In case the name of constant is
example, use 'total Amount' instead of Total too long, it should be separated by an
Amount underscore. For example, sales tax rate
should be written as 'SALES TAX_RATE’
Variable Naming Conventions Constant Naming Conventions
The temporary storage variables that are The use of literal should be avoided. Literal
restricted to a segment of code should be numbers such as ‘15' used in the software
short. For example, the variable 'temp' can code confuses the reader. These numbers
be used for temporary variable. It is are counted as integers and result in wrong
important to note that single temporary output of the program. However, the
variable should not be reused in the same numbers 0 and 1 can be used as constants.
program. For example, variables ‘I’,’J’or 'k'
are declared while using loops
* the function name should begin with a verb. for example, the verb ‘display’
can be used for the function that displays the output on the screen. in case the
verb itself is not descriptive an additional noun or adjective can be used with the
verb. for example, the function name ‘add Marks’ should be used to clarify the
function and its purpose.
* in case the function returns a Boolean value, the helping verbs ‘is’ and ‘has’
should be used as prefixes for the function name. for example, the function name
‘is Deposited’ or ‘has Deposited’ should be used for functions that return true or
false values
comments are helpful in proper understanding of the code segment used in
program. Commenting conventions should be used efficiently to make the code
easy to grasp.
Generally, two types of commenting conventions are used: file header comments
and trailing comments.
file header comments are useful in providing information related to a file as a
whole and comprise identification information such as date of creation, name of
creator and brief description of the software code.
trailing comments are used to provide explanation of a single line of code. these
comments are used to clarify the complex code. these also specify the function of
the abbreviated variable names that are not clear.
in some languages, trailing commands are used with the help of a double Slash
(//)..
The commenting conventions that are commonly followed in the software code are listed
below
• comments should be used with important segments of code and code segments that are
difficult to understand.
• comments should be used to include information that is clearly understandable from the
software.
• Comments should be separated from the code to enhance readability of the software code
• indentation should be used to highlight a nested block. some nested blocks can be made with
the help
• indentation should be used to highlight a nested block. some nested blocks can be made with
the help of ‘if else’ and ‘do while’ loops.
• indentation is required if the statement is large enough to fit in a single line.
• indentation should be consistent at the beginning and at the end of the braces in the program.
• there should be a space after placing a comma between two function arguments
• there should be no space between function name and parenthesis.
• there should be spaces to align the operators vertically to emphasize program structure and
Implementing coding guidelines:
if coding guidelines are used in a proper manner, errors can be detected at the
time of writing the software code. such detection in early stages helps in
increasing the performance of the software as well as reducing the additional and
unplanned cost of correcting and removing errors.
Moreover, if a well defined coding guideline is applied, the program yields a
software system that is easy to comprehend and maintain. some of the coding
guidelines that are followed in a programming language are listed
below.
* all the codes should be properly commented before being submitted to the
review team.
* all curly braces should start from a new line.
* all class names should start with the abbreviation of each group. for example
AA and CM can be used instead of academic administration and course
management respectively
* errors should be mentioned in the following format: [error code]: [explanation]
for example 0102:null pointer exception, where 0102 indicates the error code
and null pointer exception is the name of the error.
* every ‘if’ statement should be followed by a curly braces, even if there exist
only a single statement.
*every file should contain information about the author of the file, modification
date and version information.
similarly some of the commonly used coding guidelines in a database (organized
collection of information that is systematically organized for easy access and
analysis) are listed below.
* Table name should start with TBL. for example TBL_students
* if table names contain one word, field names should start with the first three
characters of the name of the table. for example STU_ FIRSTNAME.
➢ every table should have a primary key.
* long data type (or database equivalent) should be used for the primary key.
Incremental Software development
The incremental build model is a method of software development where
the product is designed, implemented and tested incrementally (a little
more is added each time) until the product is finished. ... The product is
defined as finished when it satisfies all of its requirements.
Incrementally developing code
The coding activity starts when some form of design has been done and the
specifications of the modules to be developed are available.
Here we discuss some effective processes that developers use for
incrementally developing code.
1)An incremental coding Process - The process followed by many
developers is to write the code for the currently assigned module, and
when done, perform unit testing on it and fix the bugs found. Then the
code is checked in the project repository to make it available to
others in the project.
Here write code for implementing only part of the functionality of the module.
This code is compiled and tested with some quick tests to check the code that has
been written so far.
When the code passes these tests, the developer proceeds to add further
functionality to the code, which is then tested again. In other words,
the code is developed incrementally, testing it as it is built.
The basic advantage of developing code incrementally with testing being done
after every round of coding is to facilitate debugging.
2)Test-Driven Development - Instead of writing code and then developing test
cases to check the code, in TDD it is the other way around—a programmer first
writes the test scripts, and then writes the code to pass the tests. The whole
process is done incrementally, with tests being written based on the
specifications and code being written to pass the tests.
In TDD, some type of prioritization for code development naturally happens.
It is most likely that the first few tests are likely to focus on using the main
functionality. Generally, the test cases for lower-priority features or functionality
will be developed later. Consequently, code for high-priority features will be
developed first and lower-priority items will be developed later.
This has the benefit that higher-priority items get done first, but has the drawback
that some of the lower-priority features or some special cases for which
test cases are not written may not get handled in the code.
3)Pair Programming – *In Pair Programming the coding work is
assigned not to an individual but to a pair of individuals.
*One person will type the program while the other will actively participate
and constantly review what is being typed. When errors are noticed, they are
pointed out and corrected. When needed, the pair discusses the algorithms,
data structures, or strategies to be used in the code to be written. The roles
are rotated frequently making both equal partners and having similar roles.
Managing Evolving Code
During this development the code undergoes changes. Besides the changes due to
the development process, code changes are also needed due to changes in
module specifications. In such a dynamic scenario, managing evolving code is a
challenge.
Here we Discuss two methods.
1)Source code Control and Build - In a project many different people develop
source code. Each programmer creates different source files, which are
eventually combined together to create executables. Programmers keep changing
their source files as the code evolves.
* A modern source code control system contains a repository, which is essentially
a controlled directory structure, which keeps the full revision history of all the
files produced by the different programmers in the project team.
* For a project, a repository has to be set up with permissions for different people
in the project. The files the repository will contain are also specified.
Programmers use the repository to make their source file changes available, as
well as obtain other source files.
*Some of the types of commands that are generally performed by a programmer
are:
a) Get a local copy - A programmer in a project works on a local copy of the file.
Commands are provided to make a local copy from the repository. Making a
local copy is generally called a checkout. A user will get the latest copy of the
file. However, if a user wants, any older version of a file can be obtained from
the repository, as the complete history is maintained. Many users can check out a
file.
b) Make changes to file(s) - The changes made to the local file by a programmer
remain local until the changes are committed back on the repository. By
committing the changes made to the local file are made to the repository, and are
hence available to others. This operation is also referred to as check in.
➢ Special Cases (also called Error Guessing)- It has been seen that programs
often produce incorrect behavior when inputs form some special cases.
For example, in an arithmetic routine, if there is a division and the divisor is
zero, some special action has to be taken, which could easily be forgotten by the
programmer. These special cases form particularly good test cases, which can
reveal errors that will usually not be detected by other test cases. Special cases
will often depend on the data structures and the function of the module. There
are no rules to determine special cases, and the tester has to use his intuition and
experience to identify such test cases.
Psychology is particularly important for error guessing. The tester should play
the “devil’s advocate” and try to guess the incorrect assumptions the programmer
could have made handled incorrectly. Then test cases are written for these
situations.
➢ State based Testing - State Transition testing, a black box testing technique, in
which outputs are triggered by changes to the input conditions or changes to 'state'
of the system.
There are some systems that are essentially stateless in that for the same inputs
they always give the same outputs or exhibit the same behavior. At a smaller level,
most functions are supposed to behave in this manner.
There are, however, many systems whose behavior is state based in that for
identical inputs they behave differently at different times and may produce
different outputs. The reason for different behavior is that the state of the system
may be different. The state of the system depends on the past inputs the system
has received. Theoretically, any software that saves state can be modeled as a state
machine. . A state model for a system has four components:
1.States - Represent the impact of the past inputs to the system.
2. Transitions - Represent how the state of the system changes from one state to
another in response to some events.3. Events - Inputs to the system.
4. Actions - The outputs for the events.
The state model shows what state transitions occur and what actions are
performed in a system in response to events.
When a state model is built from the requirements of a system, we can only
include the states, transitions, and actions that are stated in the requirements or
can be inferred from them. If more information is available from the design
specifications, then a richer state model can be built.
Sometimes making the state model may require detailed information about the
design of the system. Due to this, the state-based testing may be considered as
somewhat between black-box and white-box testing. Such strategies are
sometimes called gray-box testing.
Deriving Test cases:
Understand the various state and transition and mark each valid and invalid
state
• Defining a sequence of an event that leads to an allowed test ending state
• Each one of those visited state and traversed transition should be noted
down
• Steps 2 and 3 should be repeated until all states have been visited and all
transitions traversed
• For test cases to have a good coverage, actual input values and the actual
output values have to be generated
White box testing strategy –
Basic concepts –strategy can either be fault-based or coverage based
1.Fault-based testing- targets to detect certain types of faults. Example mutation testing
a)mutation testing - After the initial testing is complete, mutation testing is taken up.
The idea behind mutation testing is to make few arbitrary changes to a program at a
time. Each time the program is changed, it is called as a mutated program and the
change effected is called as a mutant.
A mutated program is tested against the full test suite of the program. If there exists at
least one test case in the test suite for which a mutant gives an incorrect result, then the
mutant is said to be dead. If a mutant remains alive even after all the test cases have
been exhausted, the test data is enhanced to kill the mutant. The process of generation
and killing of mutants can be automated by predefining a set of primitive changes that
can be applied to the program. These primitive changes can be alterations such as
changing an arithmetic operator, changing the value of a constant, changing a data type,
etc.
disadvantage of the mutation-based testing approach is that it is computationally very
expensive.
2.Coverage based testing- attempts to execute or cover certain elements of a
program. Example control flow based testing includes statement
coverage ,branch coverage , path coverage.
Testing criterion for Coverage based testing – the set of specific program
elements that a testing strategy requires to be executed.
One white-box testing strategy is said to be stronger than another strategy, if all
types of errors detected by the first testing strategy is also detected by the second
testing strategy, and the second testing strategy additionally detects some more
types of errors. When two testing strategies detect errors that are different at
least with respect to some types of errors, then they are called complementary.
Control flow based criteria - Let the control flow graph (or simply flow graph)
of a program P be G. A node in this graph represents a block of statements that is
always executed together.
Let the control flow graph (or simply flow graph) of a program P be G.
A node in this graph represents a block of statements that is always executed
together, i.e., whenever the first statement is executed, all other statements are
also executed. An edge (i, j) (from node i to node j) represents a possible transfer
of control after executing the last statement of the block represented by node i to
the first statement of the blockrepresented by node j. A node corresponding to a
block whose first statement is the start statement of P is called the start node of
G, and a node corresponding to a block whose last statement is an exit statement
is called an exit node .
A path is a finite sequence of nodes (n1 , n2 , ..., nk ), k > 1, such that there is an
edge (ni , ni+1 ) for all nodes ni in the sequence (except the last node nk ). A
complete path is a path whose first node is the start node and the last node is an
exit node.
1)Statement coverage(all nodes criterion) - the simplest coverage criterion is
statementcoverage, which requires that each statement of the program be executed at
least once during testing. In other words, it requires that the paths executed during
testing include all the nodes in the graph. This is also called the all-nodes criterion.
This coverage criterion is not very strong, and can leave errors undetected. For example,
if there is an if statement in the program without having an else clause, No test case is
needed that ensures that the condition in the if statement evaluates to false. This is a
serious shortcoming because decisions in programs are potential sources of errors.
As an example, consider the following function to compute the absolute value of a
number:
int abs (x)
int x;
{ if (x >= 0) x = 0 - x;
return (x) }
This program is clearly wrong. Suppose we execute the function with the set of test
cases { x=0 } (i.e., the set has only one test case). The statement coverage criterion will
be satisfied by testing with this set, but the error will not be revealed.
2)Branch coverage -branch coverage requires that each decision in the
program be evaluated to true and false values at least once during testing.
Testing based on branch coverage is often called branch testing. The
100% branch coverage criterion is also called the all-edges criterion .
Branch coverage implies statement coverage.