1. A complete test strategy #
Shift-left and shift-right.
Beyond the pyramid #
| Test type | What it proves | Tools |
|---|---|---|
| Component | a service works with its real dependencies (database, queue) started in throwaway containers | Testcontainers |
| Contract | an API provider honours what its consumers expect, without a shared environment | Pact, Spring Cloud Contract |
| Mutation | tests really catch errors: the code is altered and a test must fail | Stryker, PIT |
| Property-based | a rule holds for thousands of generated inputs | Hypothesis, fast-check |
Best practice : Code coverage tells which lines run, not whether they are checked: the mutation score is a much better indicator of test quality.
2. Performance #
Measure before users do.
Performance testing #
| Type | Question |
|---|---|
| Load | do we handle expected traffic with target response times? |
| Stress | where is the breaking point, and how does the system degrade? |
| Spike | what happens during a sudden surge (sales, campaign)? |
| Soak | do memory or connection leaks appear after hours? |
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [{ duration: '1m', target: 50 }, { duration: '3m', target: 50 }, { duration: '30s', target: 0 }],
thresholds: {
http_req_failed: ['rate<0.01'], // less than 1% errors
http_req_duration: ['p(95)<300'], // 95% of requests under 300 ms
},
};
export default function () {
const res = http.get(`${__ENV.BASE_URL}/api/produits`);
check(res, { 'status 200': (r) => r.status === 200 });
sleep(1);
}Thresholds turn a load test into a quality gate: if a threshold is crossed, k6 exits with code 99 and the pipeline fails. Always compare with a baseline measured on the previous version.
3. Chaos engineering #
Cause failures so you no longer suffer them.
Chaos engineering #
- Principles (Principles of Chaos Engineering): define a measurable steady state, state a hypothesis, inject realistic events (pod failure, latency, zone loss), experiment as close to production as possible, automate and minimize the blast radius.
- Tools: Chaos Mesh and LitmusChaos (Kubernetes), AWS Fault Injection Service, Azure Chaos Studio, Toxiproxy (network latency and cuts in tests), Gremlin.
- A game day gathers the team to play out a failure scenario: alerts, runbooks and coordination are checked, not just the technology.
apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata:
name: kill-one-cart-pod
namespace: staging
spec:
action: pod-kill
mode: one # a single pod: limited blast radius
selector:
namespaces: [staging]
labelSelectors: { app: cart }Watch out : No chaos without observability and a stop button: if you cannot measure the steady state, you cannot interpret the experiment or stop it in time.
4. In production #
The last safety net.
Testing in production #
- Canary with automated analysis: the new version gets a share of traffic and its metrics are compared with the old one (Argo Rollouts, Flagger).
- Synthetic monitoring: robots play critical journeys continuously from several regions.
- Feature flags: enable a feature for a few internal users, then widen.
- Shadow traffic: duplicate real requests to the new version without returning its responses to users.
Commands to know #
Commands to know
k6 run --env BASE_URL=https://recette.exemple.fr charge.js: load test with thresholdsecho $? # 99 = seuil dépassé: k6 exit codekubectl apply -f panne-pod.yaml: start a Chaos Mesh experimentnpx stryker run: mutation testing (JavaScript)pact-broker can-i-deploy --pacticipant panier --version $SHA --to-environment production: check contracts before deploying
