2. Review - Functions
• Functions must start with the function keyword, must contain a valid
function identifier (with variables), provide an optional list of arguments
surrounded by parentheses, even if there are none, and a block of code:
function do_something( $an_argument, $another ) {
// Code goes here
}
• Nothing from outside is visible to code in the block
• Nothing inside the block is visible outside the function
• Pass values into a function as arguments at invocation:
do_something( 'some value', "$another_value );
3. Assertion Testing
• An assertion is a predicate (true-false statement) placed in a
program to indicate that the developer thinks that the
predicate is always true at that place.
• Programmers can use assertions to help specify programs
and to reason about program correctness
• A precondition- an assertion placed at the beginning of a
section of code, determines the set of states under which the
programmer expects the code to execute
• A postcondition - placed at the end - describes the expected
state at the end of execution
4. Software Testing
• Software testing is the process of validating and verifying that
the software:
• meets requirements that guided its design and development
• works as expected (produces the desired outputs/behavior)
• satisfies the needs of stakeholders
• Automated testing is the process of writing software that
performs automated, repeatable isolated tests on a completely
separate software system called the System Under Test (SUT)
5. Types of Testing
• Assertion testing - is this statement correct? Can it be incorrect?
• Unit testing - does this function produce the expected output?
• Functional testing - does this module provide the expected functionality?
• Integration testing - do these modules work together?
• System testing - can we run this software where we need it?
• Validation testing - does it do what we said that it was supposed to do?
• Acceptance testing - is it actually useful to the intended users?
• Regression testing - now that we fixed something what else did we break?
6. Test-Driven Development
• Test-driven development is a software development process that
relies on the repetition of a very short development cycle. The
developer writes an automated test case that defines a desired
improvement or function, then produces the minimum amount of
code to pass that test and finally refactors the new code to
acceptable standards
1. Write code that describes a function that would be desirable to
have but does not yet exist
2. Run the tests to generate feedback and observe
3. Write some code that attempts to provide the function
4. Run the tests to generate feedback. Note failures and continue
to write code to produce a success
5. Repeat as necessary