Books: CO531: Software Engineering Practice: Testing
Books: CO531: Software Engineering Practice: Testing
1
Exhaustive testing Exhaustive testing ….
• Exhaustively test a method that takes two • … is generally not an option.
integer parameters. Assume
– 32-bit integers
– runs a test every 50 nanoseconds (10-9 secs)
• How long will this take?
2
Errors --Nomenclature
• looking for bugs, errors, defects, faults,
failures, features, showstoppers …
• lost marks, wrong answers, dead people,
crashed aircraft, no passports, blue screens,
any of the above (Microsoft)
• Debugging – fixing it – safely!
• Removal cost increases with time
3
The Test First (TDD) Scheme
Story Why Test-First
Understand
Never write a line of • Feedback: instant on code changes
Add one failing test
functional code without • Task orientation: focuses on problem
a broken test. Kent Beck decomposition, maintains focus, provides
Add production
code for that test steady and measurable progress
• Quality: built-in and maintained via testing
Run ALL tests
• Low-level design: context for decisions
Story Next (classes/methods, names, interfaces, …)
Rework OK
Complete Story
4
Unit Testing Unit Testing contd
• Usually tests just one particular method • Answers the question
– Is the code doing exactly what I think it should?
• Need confidence that low-level routines work • Note that this isn’t the question
before adding high level code – Does the code do what the requirements demand?
• Not concerned with formal validation of code • You need to ensure your code does what you want ALL
THE TIME
– Still need other forms of testing – Regression tests – all tests must pass NOT JUST THE NEW
• Wish to avoid the ripple effect ONES
• Unit testing helps with documentation
• Good unit testing – Tests are visible
– Better code design – Test are up-to-date and correct (because you keep running them!)
– Less time in the debugger – Code documentation (on the other hand) tends to drift
5
Unit Tests vs Function Tests Generating Test Cases
• Unit tests are local • Problem dependent -- experience
– Include integration tests
• Some general rules
– Written by (and for) programmers
– equivalence classes – one example covers many
• Function testing = higher order testing
– Does code do what the user expects?
– edge cases – what happens at the limits (< | <=)
– XP has continual customer involvement – odd cases
– Iterative function testing = minimal surprises • Illegal cases
– Done by end user (as well as programmers) – comment (assume programmers read them)
– Communication
– trap (defensive programming)
• Others: stress, performance, security, installability
6
Basic Guide to Debugging Basic Guide (contd.)
1. Recognise that there is a defect in your code 3. Why has the problem occurred?
• Check input data (program should already do this?) • Incorrect code may be a long way from the problem’s
appearance (code distance/time)
• Reproducibility
• E.g., incorrect value generated but problem not
• Identify the symptoms detected until it is used much later
2. Isolate the source of the problem • Are there similar sections of code elsewhere?
• What part of the system is causing the problem 4. Determine the fix
• Check inputs and outputs over smaller parts of the • Sometimes simple – one line
system • Sometimes catastrophic – major rewrite
• Experience counts here • Quick fix may be necessary
7
Do I Only Add Failing Tests Testing GUIs
• Never write a line of functional code • Is a form of function testing
without a broken test. Kent Beck. • XP approach is not as successful (Kent
• Doesn’t say I can’t add tests that don’t fail! Beck says so – so it must be true ☺)
• Add test if • It’s hard to do
– they show a failure (need to write code) • It’s hard to automate
– there is something special about the test • Screen shots are worth a thousand words.
• Document all tests
Whittaker’s Book
• Read his book for a really useful list of
things to try when you perform both unit
and function testing.
• Try some of these attacks out on your
project code.