- Unit Test
- Functional Test
- Integration Test
- Component Test
- Contract Test
- E2E Test
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.
- Development → QA → Publish
- Development → Automated QA → Publish
- Development & Automated QA → Publish
- 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
Type | Testing | Cost | Speed |
---|---|---|---|
E2E Test | UI, user tests | Expensive | Slow |
Integration Test | interaction between modules, classes | ||
Unit Test | function, module, class | Cheap | Fast |
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
- Support and maintain the test code persistently
- Be self-sufficient and avoid dependencies
- Create the reusable test utility to reduce repeated test scenarios
- Store the test codes separately with the production code which will be deployed
- Documentize with the test code
Structure | Functions |
---|---|
Before | beforeEach , beforeAll |
Test | Arrange , Act , Assert OR Given , When , Then |
After | afterEach , afterAll |
Arrange
,Given
: prepare an object to test the codeAct
,When
: execute the test codeAssert
,Then
: verify the test result to match with the expectation
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
, addCI/CD
- Timely: write the test code before adding new functions, refactoring, or the deployment
- 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
- 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