Basic concepts and unit testing - 219343 Software Testing

  • Published on
    30-Jun-2015

  • View
    1.833

  • Download
    2

Transcript

1. OutlineBasic concepts Testing principles Unit testing Basic concepts and unit testing 219343 Software TestingJittat Fakcharoenphol Kasetsart University November 7, 2008 2. OutlineBasic concepts Testing principles Unit testingOutline 1 Basic concepts 2 Testing principles 3 Unit testing 3. OutlineBasic concepts Testing principlesUnit testingTesting1Testing 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. OutlineBasic concepts Testing principlesUnit testingTesting1Testing 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. OutlineBasic concepts Testing principlesUnit testingTesting1Testing in not sexy.When projects fail, testing is the reason.In Europe in ancient times bearer of bad news got killed1 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. OutlineBasic concepts Testing principlesUnit testingTesting1Testing in not sexy.When projects fail, testing is the reason.In Europe in ancient times bearer of bad news got killedFollowing 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. Outline Basic concepts Testing principlesUnit testingDefinitions ”Testing is the process of establishing confidence that a program or system does what it is supposed to.” (Hetzel, 1973) 8. Outline Basic conceptsTesting principlesUnit testingDefinitions ”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. Outline Basic conceptsTesting principlesUnit testingDefinitions ”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. OutlineBasic concepts Testing principlesUnit testingDefinitions ”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. Outline Basic conceptsTesting principles Unit testingStatements “Program testing can be used to show the presence of bugs, but never to show their absence!” (Dijkstra 1969) 12. Outline Basic concepts Testing principlesUnit testingStatements “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. Outline Basic concepts Testing principles Unit testingStatements “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. Outline Basic concepts Testing principles Unit testingGoals How many testers does it take to change a light bulb? 15. Outline Basic concepts Testing principles Unit testingGoals How many testers does it take to change a light bulb? None. 16. Outline Basic concepts Testing principles Unit testingGoals 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. Outline Basic conceptsTesting principles Unit testingGoals Goals can vary. Define your mission. Find important bugs fast. 18. Outline Basic concepts Testing principlesUnit testingSpecific 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. Outline Basic concepts Testing principlesUnit testingSpecific 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. Outline Basic conceptsTesting principles Unit testingSpecific 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. Outline Basic conceptsTesting principles Unit testingSpecific 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. OutlineBasic conceptsTesting principlesUnit testingGoals: high test coverage Completeness. Ensure all requirements are implemented. 23. Outline Basic conceptsTesting principles Unit testingGoals: 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. Outline Basic concepts Testing principles Unit testingGoals: 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. Outline Basic conceptsTesting principles Unit testingGoals: how number of non critical defectsAt 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. Outline Basic conceptsTesting principlesUnit testingGoals: how number of non critical defectsAt 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. Outline Basic conceptsTesting principlesUnit testingGoals: how number of non critical defectsAt 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. OutlineBasic conceptsTesting principles Unit testingGoals: 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. Outline Basic concepts Testing principles Unit testingTools/processes needed 30. Outline Basic concepts Testing principles Unit testingTools/processes needed Defect management 31. OutlineBasic concepts Testing principles Unit testingTools/processes needed Defect management (issue trackers) 32. OutlineBasic concepts Testing principles Unit testingTools/processes needed Defect management (issue trackers) Release management 33. Outline Basic concepts Testing principlesUnit testingTesting principles2 Principles provide a general guideline.2 Materials from Graham, van Veenendall, Evans, and Black, Fundamentals of Software Testing: ISTQB Certification, Thomson, 2007. 34. Outline Basic concepts Testing principles Unit testingTesting shows presence of defect 35. OutlineBasic conceptsTesting principles Unit testingExhaustive testing is impossible 36. Outline Basic concepts Testing principles Unit testingEarly testing 37. OutlineBasic conceptsTesting principlesUnit testingExample: The Triangle Test3Given the lengths of three sides of a triangle, determine thetype of that triangle. Equilateral Isosceles Scalene 3 Taken from Black, Pragmatic Software Testing, Wiley, 2007 38. OutlineBasic concepts Testing principles Unit testingThe code that can be testedConsider 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");elseSystem.out.println("Scalene");} public static void main(String [] argv) {int a,b,c;// .... read inputcheckType(a,b,c);}} 39. OutlineBasic concepts Testing principles Unit testingThe code that can be testedConsider this code:package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test thisif((a==b) && (b==c)) program, in particularSystem.out.println("Equilateral");else if((a==b) ||(b==c) ||(a==c))method checkType?System.out.println("Isosceles");elseSystem.out.println("Scalene");} public static void main(String [] argv) {int a,b,c;// .... read inputcheckType(a,b,c);}} 40. OutlineBasic concepts Testing principles Unit testingThe code that can be testedConsider this code:package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test thisif((a==b) && (b==c)) program, in particularSystem.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 inputcheckType(a,b,c);}} 41. OutlineBasic concepts Testing principles Unit testingThe code that can be testedConsider this code:package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test thisif((a==b) && (b==c)) program, in particularSystem.out.println("Equilateral");else if((a==b) ||(b==c) ||(a==c))method checkType?System.out.println("Isosceles");else Automatically? VerySystem.out.println("Scalene"); very difficult.}Because?public static void main(String [] argv) {int a,b,c;// .... read inputcheckType(a,b,c);}} 42. OutlineBasic concepts Testing principlesUnit testingThe code that can be testedConsider this code:package lect02; public class Triangle1 { static void checkType(int a, int b, int c) { How can we test thisif((a==b) && (b==c)) program, in particularSystem.out.println("Equilateral");else if((a==b) ||(b==c) ||(a==c))method checkType?System.out.println("Isosceles");else Automatically? VerySystem.out.println("Scalene"); very difficult.}Because?public static void main(String [] argv) {It is hard to check theint a,b,c;// .... read input output of the method.checkType(a,b,c);}} 43. Outline Basic concepts Testing principles Unit testingAfter 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. OutlineBasic conceptsTesting principles Unit testingPractice Find as many interesting test cases for this method. Write in this form:Tester action and data Expected result 45. OutlineBasic conceptsTesting principles Unit testingPractice Find as many interesting test cases for this method. Write in this form:Tester action and data Expected resultWe will use this example to talk about good test set again. 46. Outline Basic conceptsTesting principlesUnit testingUnit 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 hoursand 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. OutlineBasic conceptsTesting principles Unit testingUnit 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 hoursand roughly a thousand new lines added the program would work flawlessly. Betty:Betty works hard. She codes everyday. The project deadline istomorrow. She types in about one hundred new lines per hour, and keepstesting each method she adds. She does not proceed to write new codes unlessall 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. OutlineBasic conceptsTesting principles Unit testingUnit 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 hoursand roughly a thousand new lines added the program would work flawlessly. Betty:Betty works hard. She codes everyday. The project deadline istomorrow. She types in about one hundred new lines per hour, and keepstesting each method she adds. She does not proceed to write new codes unlessall 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. Outline Basic concepts Testing principles Unit testingDeveloper Testing Revolution Developer testing is a key component in a hot paradigm: Agile/eXtreme Programming. 50. Outline Basic concepts Testing principles Unit testingDeveloper 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. Outline Basic concepts Testing principles Unit testingGood reasons for developer testingReduces unit-level bugs 52. Outline Basic conceptsTesting principles Unit testingGood reasons for developer testingReduces unit-level bugs Forces you to slow down and think 53. Outline Basic conceptsTesting principles Unit testingGood reasons for developer testingReduces unit-level bugs Forces you to slow down and think Improves design 54. Outline Basic conceptsTesting principles Unit testingGood reasons for developer testingReduces unit-level bugs Forces you to slow down and think Improves design Makes development faster 55. Outline Basic conceptsTesting principles Unit testingGood reasons for developer testingReduces unit-level bugs Forces you to slow down and think Improves design Makes development faster Tests are good documentation 56. Outline Basic conceptsTesting principles Unit testingGood reasons for developer testingReduces unit-level bugs Forces you to slow down and think Improves design Makes development faster Tests are good documentation Tests constrain features 57. Outline Basic conceptsTesting principlesUnit testingGood reasons for developer testingReduces 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. Outline Basic conceptsTesting principlesUnit testingGood reasons for developer testingReduces 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. Outline Basic conceptsTesting principlesUnit testingGood reasons for developer testingReduces 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. OutlineBasic concepts Testing principles Unit testingGoals Does the code do what I want? 61. Outline Basic concepts Testing principles Unit testingGoals Does the code do what I want? Does the code do what I want all the time? 62. Outline Basic concepts Testing principles Unit testingGoals Does the code do what I want? Does the code do what I want all the time? Can I depend on it? 63. Outline Basic concepts Testing principles Unit testingGoals 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. Outline Basic concepts Testing principlesUnit testingGoals 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. Outline Basic concepts Testing principles Unit testingTest your code It is your code, and your responsibilityDo it for your current colleaguesDo it for future generation of colleaguesDo it for yourself 66. OutlineBasic concepts Testing principles Unit testingTest early and often 67. OutlineBasic concepts Testing principles Unit testingTest early and often 68. Outline Basic concepts Testing principles Unit testingHeaven! 69. Outline Basic concepts Testing principles Unit testingHeaven! Every class has unit tests 70. Outline Basic conceptsTesting principles Unit testingHeaven! Every class has unit tests The tests are executed many times each day 71. Outline Basic concepts Testing principles Unit testingHeaven! 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. Outline Basic concepts Testing principles Unit testingHeaven! 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. Outline Basic concepts Testing principles Unit testingA unit What’s a unit? A single method/function/procedure A collection of related methods/functions/procedues 74. OutlineBasic concepts Testing principles Unit testingA unit What’s a unit?A single method/function/procedureA collection of related methods/functions/procedues Ideal world: 75. Outline Basic concepts Testing principles Unit testingA unit What’s a unit? A single method/function/procedure A collection of related methods/functions/procedues Ideal world: independent, self-sufficient, standalone 76. Outline Basic concepts Testing principles Unit testingA 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. Outline Basic concepts Testing principles Unit testingA 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. Outline Basic concepts Testing principles Unit testingBasic structure Setup Create initial states Initialize method parameters Store pre-execute values 79. Outline Basic concepts Testing principles Unit testingBasic structure Setup Create initial states Initialize method parameters Store pre-execute values Execute code 80. Outline Basic concepts Testing principles Unit testingBasic structure Setup Create initial states Initialize method parameters Store pre-execute values Execute code Compare results 81. Outline Basic concepts Testing principles Unit testingPractice: Triangle Write junit test cases for Triangle. 82. Outline Basic concepts Testing principles Unit testingDiscussion: test cases for Triangle What are your test cases? 83. OutlineBasic conceptsTesting principles Unit testingTest-driven development Traditional steps: design, code, test, design, code, test, ... 84. OutlineBasic conceptsTesting principles Unit testingTest-driven development Traditional steps: design, code, test, design, code, test, ... TDD: test, code, refactor, test, code, refactor, ... 85. OutlineBasic conceptsTesting principles Unit testingTest-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. OutlineBasic conceptsTesting principlesUnit testingTest-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. Outline Basic concepts Testing principles Unit testingTDD: Triangle See demo. 88. Outline Basic concepts Testing principles Unit testingPractice: Median

Recommended

View more >