CPSC 2140 - DAY 4 AUGUST 30, 2016 ================================================================================ A formal Contract /** @requires x>0 and epsilon > 0 @ensures sqrt >= 0 and |sqrt - x^(1/2)| / x^(1/2) <= epsilon */ There are reasoning tools that can leverage formal contracts The tools can check code. Java assert statements .to localize bugs during development, we can use assert in client or implementation code .Example assert x > 0.0 .This checking can be turned off to avoid inefficiency in production software "-ea" in JVM SOFTWARE TESTING ---------------- Quality Assurance Software is everywhere Software errors can have serious consequences Life threatening, mission threatening, infrastructure Validation and Verification --------------------------- Validation that software meets customer requirements .Focus of larger software engineering Verification that software modulel (e.g. functions and classes) meet their contracts Testing ------- Objective .Find inputs where the code is defective. .Successful tests show failures! Approach .Execute the code on selected inputs and check if it fails .Key question: What inputs have the best chance of causing defects. Formal Reasoning ---------------- Objective .Prove using mathematical means that code functions correctly - behaves as specified in its contract. .Establish code correctness on all inputs. Testing is a ubiquitous and expensive software engineering activity Best practice is to test individual units or components of software (one class, one method at a time) .This is known as unit testing .Testing what happens when multiple components are put together are called integration testing .System testing - testing the end-user system Incorrect (Defective) Code Test Plan/Test fixture A set of test cases Test boundry cases, "smallest", "largest", "special values" Test routine cases Test challenging cases i.e. the ones that are error prone Psychology of Testing --------------------- DEsign and coding are creative activities Testing is a destructive activity .The primary goal is to break the software Very often the same person does both coding and testing (not a best practice) .You need to split personality - become paranoid and malicious