Basic concepts and unit testing - 219343 Software Testing

2,102 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,102
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
53
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Basic concepts and unit testing - 219343 Software Testing

  1. 1. Outline Basic concepts Testing principles Unit testing Basic concepts and unit testing 219343 Software Testing Jittat Fakcharoenphol Kasetsart University November 7, 2008
  2. 2. Outline Basic concepts Testing principles Unit testing Outline 1 Basic concepts 2 Testing principles 3 Unit testing
  3. 3. Outline Basic concepts Testing principles Unit testing Testing1 Testing in not sexy. 1 Most of the materials on basic concepts are taken from slides developed for the course in 2007 mostly by Uwe G¨hl. (See the course homepage for that u semester.) Thanks, Uwe!
  4. 4. Outline Basic concepts Testing principles Unit testing Testing1 Testing in not sexy. When projects fail, testing is the reason. 1 Most of the materials on basic concepts are taken from slides developed for the course in 2007 mostly by Uwe G¨hl. (See the course homepage for that u semester.) Thanks, Uwe!
  5. 5. Outline Basic concepts Testing principles Unit testing Testing1 Testing in not sexy. When projects fail, testing is the reason. In Europe in ancient times bearer of bad news got killed 1 Most of the materials on basic concepts are taken from slides developed for the course in 2007 mostly by Uwe G¨hl. (See the course homepage for that u semester.) Thanks, Uwe!
  6. 6. Outline Basic concepts Testing principles Unit testing Testing1 Testing in not sexy. When projects fail, testing is the reason. In Europe in ancient times bearer of bad news got killed Following legends, even bearer of good news died ... 1 Most of the materials on basic concepts are taken from slides developed for the course in 2007 mostly by Uwe G¨hl. (See the course homepage for that u semester.) Thanks, Uwe!
  7. 7. Outline Basic concepts Testing principles Unit testing Definitions ”Testing is the process of establishing confidence that a program or system does what it is supposed to.” (Hetzel, 1973)
  8. 8. Outline Basic concepts Testing principles Unit testing Definitions ”Testing is the process of establishing confidence that a program or system does what it is supposed to.” (Hetzel, 1973) ”Testing is demonstrating that a system is fit for purpose.” (Evans et al. 1996)
  9. 9. Outline Basic concepts Testing principles Unit testing Definitions ”Testing is the process of establishing confidence that a program or system does what it is supposed to.” (Hetzel, 1973) ”Testing is demonstrating that a system is fit for purpose.” (Evans et al. 1996) ”Testing is the process of executing a program or system with the intent of finding errors.” (Myers, 1979)
  10. 10. Outline Basic concepts Testing principles Unit testing Definitions ”Testing is the process of establishing confidence that a program or system does what it is supposed to.” (Hetzel, 1973) ”Testing is demonstrating that a system is fit for purpose.” (Evans et al. 1996) ”Testing is the process of executing a program or system with the intent of finding errors.” (Myers, 1979) ”Testing is the process consisting of all life cycle activities concerned with checking software and software-related work products.” (Gelperin and Hetzel, 1988)
  11. 11. Outline Basic concepts Testing principles Unit testing Statements “Program testing can be used to show the presence of bugs, but never to show their absence!” (Dijkstra 1969)
  12. 12. Outline Basic concepts Testing principles Unit testing Statements “Program testing can be used to show the presence of bugs, but never to show their absence!” (Dijkstra 1969) “In most cases ‘what you test in a system is much more important than ‘how much you test” (Craig 2002)
  13. 13. Outline Basic concepts Testing principles Unit testing Statements “Program testing can be used to show the presence of bugs, but never to show their absence!” (Dijkstra 1969) “In most cases ‘what you test in a system is much more important than ‘how much you test” (Craig 2002) “Prioritise tests so that, when ever you stop testing, you have done the best testing in the time available.” (ISEB testing foundation course material 2003)
  14. 14. Outline Basic concepts Testing principles Unit testing Goals How many testers does it take to change a light bulb?
  15. 15. Outline Basic concepts Testing principles Unit testing Goals How many testers does it take to change a light bulb? None.
  16. 16. Outline Basic concepts Testing principles Unit testing Goals How many testers does it take to change a light bulb? None. Testers just noticed that the room was dark. Testers dont fix the problems, they just find them.
  17. 17. Outline Basic concepts Testing principles Unit testing Goals Goals can vary. Define your mission. Find important bugs fast.
  18. 18. Outline Basic concepts Testing principles Unit testing Specific goals Goal of Testing is to establish the ground for the acceptance of the software by the customer based on the specification through 1 High test coverage
  19. 19. Outline Basic concepts Testing principles Unit testing Specific goals Goal of Testing is to establish the ground for the acceptance of the software by the customer based on the specification through 1 High test coverage 2 Low number of non critical defects
  20. 20. Outline Basic concepts Testing principles Unit testing Specific goals Goal of Testing is to establish the ground for the acceptance of the software by the customer based on the specification through 1 High test coverage 2 Low number of non critical defects There should be no critical defect
  21. 21. Outline Basic concepts Testing principles Unit testing Specific goals Goal of Testing is to establish the ground for the acceptance of the software by the customer based on the specification through 1 High test coverage 2 Low number of non critical defects There should be no critical defect 3 Statements concerning software quality
  22. 22. Outline Basic concepts Testing principles Unit testing Goals: high test coverage Completeness. Ensure all requirements are implemented.
  23. 23. Outline Basic concepts Testing principles Unit testing Goals: high test coverage Completeness. Ensure all requirements are implemented. Total scope must be tested at least once (of course hopefully successful) Critical scope. Ensure that critical requirements are implemented and work fine.
  24. 24. Outline Basic concepts Testing principles Unit testing Goals: high test coverage Completeness. Ensure all requirements are implemented. Total scope must be tested at least once (of course hopefully successful) Critical scope. Ensure that critical requirements are implemented and work fine. All high prioritized requirements must be tested successfully
  25. 25. Outline Basic concepts Testing principles Unit testing Goals: how number of non critical defects At the end the final version of the application: should have no critical defects any more should have only a small number of tolerable defects
  26. 26. Outline Basic concepts Testing principles Unit testing Goals: how number of non critical defects At the end the final version of the application: should have no critical defects any more should have only a small number of tolerable defects Demand on Testing is therefore to detect as much critical defects as soon as possible idea is to fix them during the Testing phase
  27. 27. Outline Basic concepts Testing principles Unit testing Goals: how number of non critical defects At the end the final version of the application: should have no critical defects any more should have only a small number of tolerable defects Demand on Testing is therefore to detect as much critical defects as soon as possible idea is to fix them during the Testing phase The acceptance criteria should determine what the customer expects. A contract should contain acceptance criteria concerning severity level and priority level of bugs.
  28. 28. Outline Basic concepts Testing principles Unit testing Goals: Statements concerning software quality Is it possible to install the software? Is it possible to operate the software, is it compatible? Fulfils the software the expected functionality? Do the interfaces work? Is it possible to use the software optimal (Software-ergonomics, usability, end user needs) Does the software run steadily, with high performance, fail proof? Fulfils the software special cultural features (Multilingualism, English / metric system, weight units)? Is the software safe / secure?
  29. 29. Outline Basic concepts Testing principles Unit testing Tools/processes needed
  30. 30. Outline Basic concepts Testing principles Unit testing Tools/processes needed Defect management
  31. 31. Outline Basic concepts Testing principles Unit testing Tools/processes needed Defect management (issue trackers)
  32. 32. Outline Basic concepts Testing principles Unit testing Tools/processes needed Defect management (issue trackers) Release management
  33. 33. Outline Basic concepts Testing principles Unit testing Testing principles2 Principles provide a general guideline. 2 Materials from Graham, van Veenendall, Evans, and Black, Fundamentals of Software Testing: ISTQB Certification, Thomson, 2007.
  34. 34. Outline Basic concepts Testing principles Unit testing Testing shows presence of defect
  35. 35. Outline Basic concepts Testing principles Unit testing Exhaustive testing is impossible
  36. 36. Outline Basic concepts Testing principles Unit testing Early testing
  37. 37. Outline Basic concepts Testing principles Unit testing Example: The Triangle Test3 Given the lengths of three sides of a triangle, determine the type of that triangle. Equilateral Isosceles Scalene 3 Taken from Black, Pragmatic Software Testing, Wiley, 2007
  38. 38. Outline Basic concepts Testing principles Unit testing The code that can be tested Consider this code: package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { if((a==b) && (b==c)) System.out.println("Equilateral"); else if((a==b) ||(b==c) ||(a==c)) System.out.println("Isosceles"); else System.out.println("Scalene"); } public static void main(String [] argv) { int a,b,c; // .... read input checkType(a,b,c); } }
  39. 39. Outline Basic concepts Testing principles Unit testing The code that can be tested Consider this code: package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test this if((a==b) && (b==c)) program, in particular System.out.println("Equilateral"); else if((a==b) ||(b==c) ||(a==c)) method checkType? System.out.println("Isosceles"); else System.out.println("Scalene"); } public static void main(String [] argv) { int a,b,c; // .... read input checkType(a,b,c); } }
  40. 40. Outline Basic concepts Testing principles Unit testing The code that can be tested Consider this code: package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test this if((a==b) && (b==c)) program, in particular System.out.println("Equilateral"); else if((a==b) ||(b==c) ||(a==c)) method checkType? System.out.println("Isosceles"); else Automatically? System.out.println("Scalene"); } public static void main(String [] argv) { int a,b,c; // .... read input checkType(a,b,c); } }
  41. 41. Outline Basic concepts Testing principles Unit testing The code that can be tested Consider this code: package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test this if((a==b) && (b==c)) program, in particular System.out.println("Equilateral"); else if((a==b) ||(b==c) ||(a==c)) method checkType? System.out.println("Isosceles"); else Automatically? Very System.out.println("Scalene"); very difficult. } Because? public static void main(String [] argv) { int a,b,c; // .... read input checkType(a,b,c); } }
  42. 42. Outline Basic concepts Testing principles Unit testing The code that can be tested Consider this code: package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test this if((a==b) && (b==c)) program, in particular System.out.println("Equilateral"); else if((a==b) ||(b==c) ||(a==c)) method checkType? System.out.println("Isosceles"); else Automatically? Very System.out.println("Scalene"); very difficult. } Because? public static void main(String [] argv) { It is hard to check the int a,b,c; // .... read input output of the method. checkType(a,b,c); } }
  43. 43. Outline Basic concepts Testing principles Unit testing After some fix package lect02; public class Triangle { enum Type { Equilateral, Isosceles, Scalene } static Type checkType(int a, int b, int c) { if((a==b) && (b==c)) return Type.Equilateral; else if((a==b) ||(b==c) ||(a==c)) return Type.Isosceles; else return Type.Scalene; } }
  44. 44. Outline Basic concepts Testing principles Unit testing Practice Find as many interesting test cases for this method. Write in this form: Tester action and data Expected result
  45. 45. Outline Basic concepts Testing principles Unit testing Practice Find as many interesting test cases for this method. Write in this form: Tester action and data Expected result We will use this example to talk about good test set again.
  46. 46. Outline Basic concepts Testing principles Unit testing Unit testing: classic example4 John: John works hard. He codes everyday. The project deadline is tomorrow. He types in about two hundred new lines per hour, and thinks that after 6 hours and roughly a thousand new lines added the program would work flawlessly. 4 Materials regarding unit testing concepts are from Alberto Savoia’s slides and George Necular’s software engineering course
  47. 47. Outline Basic concepts Testing principles Unit testing Unit testing: classic example4 John: John works hard. He codes everyday. The project deadline is tomorrow. He types in about two hundred new lines per hour, and thinks that after 6 hours and roughly a thousand new lines added the program would work flawlessly. Betty: Betty works hard. She codes everyday. The project deadline is tomorrow. She types in about one hundred new lines per hour, and keeps testing each method she adds. She does not proceed to write new codes unless all previously written pieces work correctly. 4 Materials regarding unit testing concepts are from Alberto Savoia’s slides and George Necular’s software engineering course
  48. 48. Outline Basic concepts Testing principles Unit testing Unit testing: classic example4 John: John works hard. He codes everyday. The project deadline is tomorrow. He types in about two hundred new lines per hour, and thinks that after 6 hours and roughly a thousand new lines added the program would work flawlessly. Betty: Betty works hard. She codes everyday. The project deadline is tomorrow. She types in about one hundred new lines per hour, and keeps testing each method she adds. She does not proceed to write new codes unless all previously written pieces work correctly. Guess who will go to bed earlier? 4 Materials regarding unit testing concepts are from Alberto Savoia’s slides and George Necular’s software engineering course
  49. 49. Outline Basic concepts Testing principles Unit testing Developer Testing Revolution Developer testing is a key component in a hot paradigm: Agile/eXtreme Programming.
  50. 50. Outline Basic concepts Testing principles Unit testing Developer Testing Revolution Developer testing is a key component in a hot paradigm: Agile/eXtreme Programming. The Developer Testing Trinity: Test Test early and often Test well
  51. 51. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs
  52. 52. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think
  53. 53. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think Improves design
  54. 54. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think Improves design Makes development faster
  55. 55. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think Improves design Makes development faster Tests are good documentation
  56. 56. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think Improves design Makes development faster Tests are good documentation Tests constrain features
  57. 57. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think Improves design Makes development faster Tests are good documentation Tests constrain features Tests allows safe refactoring and reduce the cost of change
  58. 58. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think Improves design Makes development faster Tests are good documentation Tests constrain features Tests allows safe refactoring and reduce the cost of change Tests defend against other programmers
  59. 59. Outline Basic concepts Testing principles Unit testing Good reasons for developer testing Reduces unit-level bugs Forces you to slow down and think Improves design Makes development faster Tests are good documentation Tests constrain features Tests allows safe refactoring and reduce the cost of change Tests defend against other programmers Tests reduce fear
  60. 60. Outline Basic concepts Testing principles Unit testing Goals Does the code do what I want?
  61. 61. Outline Basic concepts Testing principles Unit testing Goals Does the code do what I want? Does the code do what I want all the time?
  62. 62. Outline Basic concepts Testing principles Unit testing Goals Does the code do what I want? Does the code do what I want all the time? Can I depend on it?
  63. 63. Outline Basic concepts Testing principles Unit testing Goals Does the code do what I want? Does the code do what I want all the time? Can I depend on it? Also: get a document for the code.
  64. 64. Outline Basic concepts Testing principles Unit testing Goals Does the code do what I want? Does the code do what I want all the time? Can I depend on it? Also: get a document for the code. Plus: Always correct documentation for your intention.
  65. 65. Outline Basic concepts Testing principles Unit testing Test your code It is your code, and your responsibility Do it for your current colleagues Do it for future generation of colleagues Do it for yourself
  66. 66. Outline Basic concepts Testing principles Unit testing Test early and often
  67. 67. Outline Basic concepts Testing principles Unit testing Test early and often
  68. 68. Outline Basic concepts Testing principles Unit testing Heaven!
  69. 69. Outline Basic concepts Testing principles Unit testing Heaven! Every class has unit tests
  70. 70. Outline Basic concepts Testing principles Unit testing Heaven! Every class has unit tests The tests are executed many times each day
  71. 71. Outline Basic concepts Testing principles Unit testing Heaven! Every class has unit tests The tests are executed many times each day The tests are thorough, up to date, and easy to maintain and analyze
  72. 72. Outline Basic concepts Testing principles Unit testing Heaven! Every class has unit tests The tests are executed many times each day The tests are thorough, up to date, and easy to maintain and analyze In this class, we shall aim for that.
  73. 73. Outline Basic concepts Testing principles Unit testing A unit What’s a unit? A single method/function/procedure A collection of related methods/functions/procedues
  74. 74. Outline Basic concepts Testing principles Unit testing A unit What’s a unit? A single method/function/procedure A collection of related methods/functions/procedues Ideal world:
  75. 75. Outline Basic concepts Testing principles Unit testing A unit What’s a unit? A single method/function/procedure A collection of related methods/functions/procedues Ideal world: independent, self-sufficient, standalone
  76. 76. Outline Basic concepts Testing principles Unit testing A unit What’s a unit? A single method/function/procedure A collection of related methods/functions/procedues Ideal world: independent, self-sufficient, standalone Real world:
  77. 77. Outline Basic concepts Testing principles Unit testing A unit What’s a unit? A single method/function/procedure A collection of related methods/functions/procedues Ideal world: independent, self-sufficient, standalone Real world: lots of dependence
  78. 78. Outline Basic concepts Testing principles Unit testing Basic structure Setup Create initial states Initialize method parameters Store pre-execute values
  79. 79. Outline Basic concepts Testing principles Unit testing Basic structure Setup Create initial states Initialize method parameters Store pre-execute values Execute code
  80. 80. Outline Basic concepts Testing principles Unit testing Basic structure Setup Create initial states Initialize method parameters Store pre-execute values Execute code Compare results
  81. 81. Outline Basic concepts Testing principles Unit testing Practice: Triangle Write junit test cases for Triangle.
  82. 82. Outline Basic concepts Testing principles Unit testing Discussion: test cases for Triangle What are your test cases?
  83. 83. Outline Basic concepts Testing principles Unit testing Test-driven development Traditional steps: design, code, test, design, code, test, ...
  84. 84. Outline Basic concepts Testing principles Unit testing Test-driven development Traditional steps: design, code, test, design, code, test, ... TDD: test, code, refactor, test, code, refactor, ...
  85. 85. Outline Basic concepts Testing principles Unit testing Test-driven development Traditional steps: design, code, test, design, code, test, ... TDD: test, code, refactor, test, code, refactor, ... We’ll discuss more about TDD later.
  86. 86. Outline Basic concepts Testing principles Unit testing Test-driven development Traditional steps: design, code, test, design, code, test, ... TDD: test, code, refactor, test, code, refactor, ... We’ll discuss more about TDD later. For now, let’s do it a little.
  87. 87. Outline Basic concepts Testing principles Unit testing TDD: Triangle See demo.
  88. 88. Outline Basic concepts Testing principles Unit testing Practice: Median

×