Skip to content

Latest commit

 

History

History
125 lines (93 loc) · 5.23 KB

README.md

File metadata and controls

125 lines (93 loc) · 5.23 KB

Test Driven Development

Index

  1. About Testing
    1. Types of Test
    2. What is Testing
    3. History of Testing
    4. Advantage of Testing
    5. Test Pyramid
    6. Jest
  2. Testing Principles
    1. Secrets of Test Code
    2. Structure of Test
    3. FIRST
    4. Right-BICEP
    5. Test Coverage: CORRECT
  3. References

1. About Testing

1.1. Types of Test

  • Unit Test
  • Functional Test
  • Integration Test
  • Component Test
  • Contract Test
  • E2E Test

1.2. What is Testing

The term testing is refer to software testing. It means testing an application, function, service, UI, performance or an APIs specs to qualify the quality of the service. Also find any software bugs. Ultimately, this is a job to check if a service work as what we expected.

1.3. History of Testing

  • Development → QA → Publish
  • Development → Automated QA → Publish
  • Development & Automated QA → Publish

1.4. Advantage of Testing

  • Expect the operation
  • Qualify the requirements
  • Predictable issues
  • Find bugs easily
  • Easy refactoring
  • Easy maintenance
  • Code quality improvement
  • Reduce code dependencies
  • Easy to document
  • Reduce development time

1.5. Test Pyramid

Test Pyramid

Type Testing Cost Speed
E2E Test UI, user tests Expensive Slow
Integration Test interaction between modules, classes
Unit Test function, module, class Cheap Fast

1.6. Jest

Jest is a JavaScript Testing Framework with a focus on simplicity. It had been designed to ensure correctness of any JavaScript codebase. It works with projects using: Babel, TypeScript, Node, React, Angular, Vue and more.

  • zero config
  • snapshots
  • isolated
  • great api

2. Testing Principles

2.1 Secrets of Test Code

  1. Support and maintain the test code persistently
  2. Be self-sufficient and avoid dependencies
  3. Create the reusable test utility to reduce repeated test scenarios
  4. Store the test codes separately with the production code which will be deployed
  5. Documentize with the test code

2.2 Structure of Test

Structure  Functions
Before beforeEach, beforeAll
Test Arrange, Act, Assert OR Given, When, Then
After afterEach, afterAll
  • Arrange, Given: prepare an object to test the code
  • Act, When: execute the test code
  • Assert, Then: verify the test result to match with the expectation

2.3 FIRST

FIRST

  • Fast: remove dependencies to reduce test time (files, database, network)
  • Isolated: test isolated code to prove the unit test
  • Repeatable: must return the same result all the time (should not be effected by environment or network)
  • Self-Validating: validate the test with the Jest API: expect, toBe, toEqual, add CI/CD
  • Timely: write the test code before adding new functions, refactoring, or the deployment

2.4 Right-BICEP

  • Boundary conditions: test all the cases include null, undefined, special character, invalid format of email, small number, big number, duplicate, mis-ordered
  • Inverse relationship: must return to the original state by inverse behaviour
  • Cross-check: is a way of ensuring that everything adds up and balances, much like the general ledger in a double-entry bookkeeping system
  • Error conditions: handling all error conditions such as network error, lack of memory, database
  • Performance characteristics: test the performance by specific results

2.5 Test Coverage: CORRECT

  • Conformance: test case must follow the format of phone number, email, id, file extension
  • Ordering: test case must follow the order
  • Range: test case must tested within the range (handle the error for the test with out of range)
  • Reference: test all conditions with/without the reference of the unit test
  • Existence: handle all test cases with the null, undefined, '', 0
  • Cardinality: test with 0-1-N rule
  • Time: test unordered case, time delay, locale time

References