This repository contains the source code used for an internal training sessions at Sykes Cottages. Its purpose is to demonstrate different testing techniques.
The solutions are provided with each exercise and if you want to challenge yourself delete the test code.
- Docker
- Docker-compose
- Python >= 3.9
Each exercise contains boilerplate code to run the tests without additional setup and can be run with a single shell script.
You can run each exercise with:
./run-tests.sh
As a member of the finance team, I need a calculator system that can add two whole numbers together and provide me with the sum of those numbers.
Write some the code and tests to satisfy the story.
We just need some basic code and a simple unit test.
As a member of the finance team, I need a till system that can store a whole number running total, allow me to add a whole number to the running total using the previous calculator system and get the running total.
Write some the code and tests to satisfy the story.
Expand off the previous exercise and build the till on top of the calculator.
As a member of the customer service team, I need to be able to store a customer's forename, surname and a valid email address. I also want the ability to retrieve a customer by a unique identifier.
The code already exists, so write some code to prove that the code does what it's supposed to.
Code integrates with MySQL and we have provided a DatabaseTestCase
class to truncate and seed data for testing.
There are two functions available;
- the first is
truncateTable
to help clear a database table - the other is
runSeedData
which runs requires you to overload theseedData
function and return the following structure:
[
'TABLE_NAME' => [
[
'COLUMN_1' => 'VALUE_1',
'COLUMN_2' => 'VALUE_2'
]
]
]
public function setUp(): void
{
parent::setUp();
$this->truncateTable('customers');
$this->runSeedData();
}
public function tearDown(): void
{
$this->truncateTable('customers');
}
public function seedData(): array
{
return [
'customers' => [
[
'customer_id' => '1',
'customer_forename' => 'test',
'customer_surname' => 'test',
'customer_email' => '[email protected]'
]
]
];
}
As a member of the customer service team, I need to be able to store a customer's forename, surname and a valid email address. I also want the ability to retrieve a customer by a unique identifier.
The application already exists, so write some code to prove that the code does what it's supposed to.
Application already exists and running within the docker network.
We have provided a RequestTestCase
class to help you test the customer API.
The controller is called customer
with both GET
and POST
methods.
$this->request(
'GET',
'customer',
[
'id' => 1
]
);
$this->request(
'POST',
'customer',
[],
[
'forename' => 'test',
'surname' => 'test',
'email' => '[email protected]'
]
);