Download - Unit testing.pptx [repaired]
Unit TestingBy Mohamad Asmar
a.k.a DaiGooR
Developer life !
the more pressure you feel, the fewer tests
you writes.
The fewer tests you write, the less
productive you are and the less stable your
code becomes.
The less productive and accurate you are,
the more pressure you feel.
Def.
Wikipedia : unit testing is a software
testing method by which individual units
of source code
In a simple way … validate each and
every unit of the software perform as
designed.
Def. Cont.
A Unit is the smallest part of code›{function or procedure}
›The smallest part that can be compiled by it
self.
Ex
public int stringToInt( String str ){
return Integer.parseInt(str);
}
stringToInt(null);
stringToInt(“TEXT”)
stringToInt(“1234567890987654321”)
Why ?
Without it defects will appear at the end
of the cycle!
Trace bugs is time consuming , hard and
complex
Check new feature if they are feasible
Check input and output values
Correct outputs fast
Why ? -_-
Reduce future cost !
Faster development
Better design
Faster debugging
Excellent regression tool
+
it provide sort of documentation
Categories
White-Box : function exe and checked
Black-Box : input/output & app-interface
Types
Positive test (end user testing)›Valid parameter
Negative test ›Not valid parameter
Ex
public int stringToInt( String str ){
return Integer.parseInt(str);
}
stringToInt(null)//N
stringToInt(“TEXT”)//N
stringToInt(“1234567890987654321”)//N
stringToInt(“1234”)//P
When to write the test?
“Whenever you are tempted to type
something into a print statement or a
debugger expression, write it as a test
instead.”...
story
:$
Traditional Testing Strategies
Print Statements
Use of Debugger
Debugger Expressions
Ex.
... List<?> getVersionsForProductId(Long id){ … return List<?> }
The Tests That Are Needed
Starting from the easiest to the hardest:
If there’s no product for that id, then an exception is thrown.
If there’s no versions for a valid product id, then an empty list is
returned.
If there are versions for a product id, then a non-empty list of all the
versions is returned.
Live Show
Eclipse
IntelliJ Idea
Keep Unit tests small and fast We should run them after each checkin
keep them UN-dependent
They should not depend on each other
They should be simple
Fix error immediately
Its all about unit There should be a test class per each class .. no
more no less ! You should not right an application
to test another application.
Start with the simple test
Code convention