Automated Testing and CI Pipelines¶
What is the problem with manual testing?¶
- tedious
- some scenarious are hard to repeat
- eg. network issues, database randomly crashes
- repetitive
- growning number of scenarios
- time consuming
Cost Savings
Scenarios that are hard to repeat - Network Requests
1 2 3 4 5 6 7 8 9 10 |
|
This is the way to simulate an exception after a network request.
1 2 3 4 |
|
Importance of Software¶
Before you can truly understand why testing is important, we first have to understand the importance of software.
Importance of software in different parts
Control Systems
Healthcare
Transportations
Daily life
Office Work
Education
Software is Fragile¶
Quote
It only takes a character difference to prevent a software from compiling or running.
Consequences of Fault Softwares¶
Huge Compute Charges
Embarrassment
Disruptions
User Frustations
Client loss
Death
Automated Testing¶
What is involved manual testing usually?¶
To be able to automate testing, we need to understand what is involved in manual testing.
- Open your own environment and tools
- Git checkout/pull/fetch
- Install dependency
- Setup the environment
- Do you need to clear the database?
- Do you need to enter a couple of data?
- Do you need to disconnect the internet while server is running?
- Perform the steps to test
- Assert the test correction?
- Did you make a mistake? (repeat the entire thing)
- Now do a different scenario!
- Hang on a sec? Your coworker forgot to push? Now do all scenarios again
How does automated testing work?¶
- Write scripts to evaluate code
- Write script to run scripts when certain events happen (more so later)
- Update Scripts whenever change happens
Example from the workshop with github actions - Software Engineering Practices
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
Test-Driven Development¶
Define test/specification first, then write functionality. Works best if you know way ahead of time what you want.
Note: This does not always work (eg. Frontend)
Simple Example
1 2 |
|
1 2 |
|
More complex example, but demonstrates how it can save time
Let say you have to develop a function that sends email depending on the number of users in the database
1 2 3 4 5 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Usual workflow:
- Prepare your tools - mail client and smtp server
- Prepare your database
- Do manual testing + Write code (repeat)
- Write Automated testing
Test Driven development workflow (also known as red-green-refactor):
- Write the Automated Testing - when this is run it will fail
- Write code until test pass
- Refactor + improve code
GIVEN-WHEN-THEN¶
Acceptance of features can be divided into: - GIVEN – what are the assumptions - WHEN – occurence - THEN - effect or observation
What is CI/CD?¶
Scripts that runs for certain events (such as pull request, a commit) to run test or deploy
Providers
- Github Actions
- Circle CI
- Bitbucket Pipelines
- Travis CI
What's usually in CI?¶
- Linting (code consistency + undefined variables)
- Tests
- Builds + Deploy
Others: - bot to auto tag issue - Security checks - Code Autosuggestion (kinda like linting, but it suggests stuff)
Testing Artifacts¶
Files given when testing
Coverage Report
Cypress Screenshots + Videos
Long term test reports
Demo - Cypress Integration Test / E2E Test¶
Cypress is a tool that simulates user interaction by programatically performing action against a browser.
Get started at Cypress.