"Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.
Software testing can also provide an objective, independent view of the software [...]. Test techniques include, but are not limited to the process of executing a program or application with the intent of finding software bugs". (Wikipedia, 2013)
"Software testing can be stated as the process of validating and verifying that a computer program/application/product:
- meets the requirements that guided its design and development,
- works as expected,
- can be implemented with the same characteristics,
- and satisfies the needs of stakeholders."
Static testing is a form of software testing focusing on checking the sanity of the code. This type of testing is often used by the developer who wrote the code, but can be used also in team environments.
Dynamic testing refers to the examination of the response from the system when a software runs. It involves working with the software, giving input values and checking if the output is as expected by executing specific test cases.
The main levels of testing during the development process are:
Unit testing refers to tests that verify the functionality of a specific section of code, usually at the function level (procedural programming) or at class level (OO programming).
These types of tests are usually written by developers as they work on code, to ensure that the specific function is working as expected.
In PHP, unit testing is typically done using PHPUnit.
Integration testing is used to verify the interfaces between components. Integration tests aim to test a web application as a whole and is specifically important when different developers are working at different parts of the system.
"Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily – leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly." (Fowler, 2006)
System testing tests a completely integrated system to verify that it meets its requirements. A PHP as well as working as expected in an environment that reflects the real-use conditions.
Example of system testing tecniques used to test web applications include:
Acceptance testing is the final test conducted to determine if the requirements of a specification are met.
Expecially when it comes to web applications, testing the controller, or the model in isolation doesn't prove your application is working.
At this stage, we are not going to cover unit, integration or system testing any further - but we are going to focus on acceptance testing using CodeCeption.
Before we start using CodeCeption, you need to familiarise yourself with another tool - Putty.
PuTTY is an Open Source software that can be used as a terminal emulator.
It allows remote access to a server, and we are going to use it to connect through SSH to mastodon.
This will allow us to run some PHP scripts that require command-line access.
In the Host Name (or IP address) field enter the name of the computer you wish to connect to, select SSH as protocol and open the connection.
You should already be familiar with the main main Linux shell commands (
chmod) but we are going to review them in the next slides.
You are going to need them. If you need a full guide, you can start with this tutorial.
||To switch to any other directory||
||To create folder||
||To delete any file||
|To delete a folder and all the files inside||
chmod is used to set the permissions for your files.
Permissions tell UNIX what can be done with that file and by whom. There are three operations you can (or can't) perform with a given file or folder:
Unix permissions specify what can the owner do, what can the owner's group do, and what can everybody else do with the file.
Basic permissions are set using a triplet. The first number identifies the permission for the user, the second for the group and the third for everyone else.
Your folders should have a permission of 755 (see below) and your PHP files should have a permission of 644.
Each permission digit is calculated by summing the value permissions that should be allocated. For now, you should not need to change the permissions - and you can use WinSCP to do it through a graphical interface.
We have already been invoking PHP from the command line (e.g. in Notepad++ or in the dos prompt).
The next activities use a similar approach - but require you to have access to the development environment in Mastodon.
In the next slides we are looking at how to use CodeCeption to test our PHP applications.
CodeCeption can be used to run a wide range of tests, but we are going to focus on acceptance testing.
To use CodeCeption you need command line access. You cannot run the tests simply from a browser interface, but you will need a shell to bootstrap your test environment and create your skeleton files.
<?php $I = new AcceptanceTester($scenario); $I->wantTo('ensure that frontpage works'); $I->amOnPage('/'); $I->see('Home'); ?>
To install and bootstrap CodeCeption, please complete the next activity.
You will also need an application to test; as a first step, we can test some of the activities that we have written earlier on.
The next slide includes the step-by-step instructions to run the installation of CodeCeption.
Here is a possible step-by-step solution. Do not just copy and run the code - make sure that you understand it:
php -r "readfile('https://getcomposer.org/installer');" | php php composer.phar require "codeception/codeception: 1.8.7" wget http://codeception.com/releases/1.7.4/codecept.phar php codecept.phar bootstrap
tests/acceptance.suite.yml : the variable
url should point to your web home in mastodon (e.g. http://mastodon.uel.ac.uk/~u1234567/)
The first step to write your first step is to generate a stub (you can replace
Welcome in the code sample below with the name of your page/activity/feature):
php codecept.phar generate:cept acceptance Welcome
tests/acceptance/WelcomeCept.php to test the page (please refer to the CodeCeption quickstart and to the documentation).
To run the test, run:
php codecept.phar run
Write some basic tests for your older activities from the "PHP and NoSQL" lessons:
You can use CodeCeption to test is features work as expected. For example, to see if a form is accepting a correct combination of user names and passwords (or refusing a wrong one).
<?php $I = new AcceptanceTester($scenario); $I->wantTo('perform actions and see result'); $I->wantTo('log in as regular user'); $I->amOnPage('/lecture9_form.php'); $I->fillField('name','john'); $I->fillField('password','savage'); $I->click('submit'); $I->expect('to be logged in'); $I->see('You are now logged in in the system.') ?>
This is what you can see after calling the CodeCeption test for that form page:
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License