3. 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.
4. Def.
Wikipedia :unit testingis asoftware testingmethod by which individual units ofsource code
In a simple way … validate each and every unit of the software perform as designed.
5. Def. Cont.
A Unit is the smallest part of code
›{function or procedure}
›The smallest part that can be compiled by it self.
6. Ex
public int stringToInt( String str ){ return Integer.parseInt(str); }
stringToInt(null);
stringToInt(“TEXT”)
stringToInt(“1234567890987654321”)
7. 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
8. Why ? -_-
Reduce future cost !
Faster development
Better design
Faster debugging
Excellent regression tool +
it provide sort of documentation
11. Types
Positive test (end user testing)
›Valid parameter
Negative test
›Not valid parameter
12. Ex
public int stringToInt( String str ){ return Integer.parseInt(str); }
stringToInt(null)//N
stringToInt(“TEXT”)//N
stringToInt(“1234567890987654321”)//N
stringToInt(“1234”)//P
13. 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.”...
18. 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
19. 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