Lecture-8 Imp&Testing (2)
Lecture-8 Imp&Testing (2)
Lecture 8
Software Implementation and
Testing
Reading:
Software engineering, 9th edition (ian
sommerville)
The Art of Unit Testing, Ch. 7 (Osherove)
SW Implementation
• Converting design to language specific code
• Requires knowledge of programing language,
frameworks and API
• Those who are assigned this role called
“Programmers”
• Better practice :
– Use familiar language on implementation
– Write an easy and flexible code that can be modified
easily
– Use version control tools for better team work
– Use open source products
2
Cont’d
Here are some aspects of implementation that are
particularly important to software engineering that are
language independent.
1. Reuse: functions and objects in programming
language libraries
• The abstraction level
• The object level: find appropriate libraries and discover
if the objects and methods offer the functionality that
you need. Eg. JavaMail library.
3
Cont’d
• The component level: build your components using a
framework. Eg. display mangt: add connections to the
data to be displayed and write code to define specific
display details such as screen layout and colors.
• The system level
7
Faults and errors
• error: incorrect software behavior
– example: Message box said, "Welcome, null!"
– Example: Software controller for the Ariane
5 rocket crashed (and so did the rocket).
• fault: mechanical or algorithmic cause of
error (bug)
– example: Account name field is not set
properly.
– Requirements specify desired behavior;
if the system deviates from that, it has a
fault.
8
Quality control
techniques
• fault avoidance: Prevent errors before system is
released.
– reviews, inspections, walkthroughs,
development methodologies, configuration management
9
Testing vs Verification
• Testing – Detects the presence of bugs by running the
code on a few carefully chosen inputs
• Verification – Shows the absence of bugs on all
possible inputs
10
Some kinds of testing
• unit testing: Looks for errors in subsystems in
isolation.
• Be systematic
– If you thrash(did not handle well) about arbitrarily, the
bugs will hide in the corner until you're gone
12
Four basic steps for a
test
This is hard! Need a set of test
cases that is small enough to
run quickly, yet large enough
to cover [all] interesting
• 1. Choose input data
program behaviors.
– without looking at the implementation: black box
– with knowledge of the implementation: white box
13
Choosing Input: two key
ideas
• Partition the input space
– Identify subdomains with the same
behavior
– Pick one input from each subdomain
• Boundary values
– Pick inputs at the edges of the
subdomains.
– Effective at finding corner
case bugs:
14
Partitioning the input
space
// returns the maximum of a, b
public static int max(int a, int b) { ... }
• Partition into
– a<b,a=b,a>b
15
Choosing Boundary
Values
// returns|x|
public static int abs(int a) { ... }
• Partition into
– a<0, a>0, a=0(boundary)
16
Black box testing
• Explores alternate paths through the specification.
– Module under test is a black box: interface visible,
internals hidden.
• 3 paths, so 3 subdomains
– (1,2)=>2
– (2,1)=>2
– (0,0)=>0
17
White box testing
• Explores alternate paths through the implementation
3 Main White Box Testing Techniques:
1. Statement Coverage: it is the method of checking
whether each and every line of the code is executed at
least once.
2. Branch Coverage:
In case of an “IF statement”, there will be
two test conditions:
• One to validate the true branch and,
• Other to validate the false branch.
3. Path Coverage
Path coverage tests all the paths of the program(large
and complicated program) 18
Example
INPUT A & B
C=A+B
IF C>100
PRINT “ITS DONE”
• Test case (A=40 and B=70), then all the lines of code
will be executed.
• What if I consider my Test case as A=33 and B=45?
INPUT A & B
C=A+B
IF C>100
PRINT “ITS DONE”
ELSE
PRINT “ITS PENDING”
19
Other things to consider
• Maintenance plan/manual : includes operating
procedures, schedules, emergency protocols …etc
• Training manual: a comprehensive document
explaining your company’s policies, procedures,
products, clients, projects.
You can represent this using charts, video, visuals ,
practical examples.
Reading Assignment
21
From Problem to Code
What we are expected to do :
22
Use Case
• <<player>>
Description:
A player at random offers a guess of a coin flip .the other player gets
the other option .The coin is flipped and correct guess wins
23
Formal Description
• Use case Name : Predict Coin Flip
• Use Case Id : UC01
• Trigger : A player at random offers a prediction
• Actors :
– A player who makes prediction(Primary Actor)
– A player that gets other option
– A coin
– Coin Game
• Precondition :
– Two players must be available
– A coin must be available
• Goal : One player wins and the other loss
24
Formal Description …
• Main Success Scenario :
1. The player starts the game
2. The game picked a player to predict a coni flip
3. The player picked offers a prediction of a coin flip
4. The game provide other player remining flip option
5. The game flips the coin is flipped
6. The game provides the result
7. The game picked the winner and losers
8. The game Offers to try again
Extension
??
Alternative
?? 25
Component and
Deployment Diagram
Play Request
Game Game Service
Client PC
Game Requester
Component diagram
Deployment diagram
• Architectural style [client server model] : since java follows client server
model and we prefer performance and over the other design goal
• We can divide game service component to coin ,player and game flipper
component but it is too small to consider as components so all components
are deployed under the same package 26
Design Class Diagram
27
Implementation
• This are the implementation classes
– Coin class [Coin.java]
– Player class [Player.java]
– CoinGame class [CoinGame.java]
– CoinFlippingGame class [CoinFlippingGame.java]
• The main class [For Testing]
28
More Ideas
• Design Patterns
– Solutions to existing problems in software engineering
• Continuous integration
– Used to deploy as you code (automatically from your code
base)
– Check out travisCI
• Code review
– Review each others code before deploying
29