Files
lobehub/docs/development/basic/test.mdx
René Wang 3dfc86fd0f feat: Update user guide & changelog (#11518)
* feat: Redesign doc

* chore: uopdate site

* chore: uopdate site

* chore: uopdate site

* chore: uopdate site

* chore: uopdate site

* feat: Uopdate content

* chore: New doc

* chore: Update content

* chore: Update content

* chore: add images

* chore: add images

* chore: add images

* chore: add images

* feat: Add more images

* feat: Add more images

* fix: Cannot reach end

* chore: Update content

* chore: Update content

* chore: Update content

* chore: Update content

* chore: Update content

* Revise README content and structure

Updated README to reflect changes in project description and removed outdated notes.

* Revise 'Getting Started' and TOC in README

Updated the 'Getting Started' section and modified the table of contents.

* chore: Update content

* Revise README structure and content

Updated the Getting Started section and removed the Table of Contents. Adjusted the Local Development instructions.

* Remove custom themes section from README

Removed section about custom themes from README.

* Update README.md

* Refine introduction and highlight cloud version

Updated wording for clarity and added recommendation for cloud version.

* chore: Update content

* chore: Update content

* chore: Update content

* chore: Update content

* chore: Update content

* chore: Update content

* chore: Update content

* fix: add missing translation

* 🔀 chore: Move README changes to feat/readme branch

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: add missing translation

* chore: update cdn

* docs: add migration guide from v1.x local database to v2.x and update help sections

Signed-off-by: Innei <tukon479@gmail.com>

* fix: add missing translation

* fix: add missing images

* fix: add missing changelogs

* fix: add missing changelogs

* fix: add missing changelogs

* fix: add missing changelogs

* fix: add missing changelogs

* style: update cdn

---------

Signed-off-by: Innei <tukon479@gmail.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: canisminor1990 <i@canisminor.cc>
Co-authored-by: Innei <tukon479@gmail.com>
2026-01-26 15:28:33 +08:00

93 lines
3.7 KiB
Plaintext

---
title: Testing Guide
description: >-
Explore LobeHub's testing strategy, including unit and end-to-end testing
methods.
tags:
- LobeHub
- Testing
- Unit Testing
- End-to-End Testing
- vitest
---
# Testing Guide
LobeHub's testing strategy includes unit testing and end-to-end (E2E) testing. Below are detailed explanations of each type of testing:
## Unit Testing
Unit testing is used to test the functionality of independent units in the application, such as components, functions, utility functions, etc. We use [vitest][vitest-url] for unit testing.
To run unit tests, you can use the following command:
```bash
npm run test
```
This will run all unit tests and generate a test report.
We encourage developers to write corresponding unit tests while writing code to ensure the quality and stability of the code.
## 🚧 End-to-End Testing
End-to-end testing is used to test the functionality and performance of the application in a real environment. It simulates real user operations and verifies the application's performance in different scenarios.
Currently, there is no integrated end-to-end testing in LobeHub. We will gradually introduce end-to-end testing in subsequent iterations.
## Development Testing
### 1. Unit Testing
Unit testing is conducted on the smallest testable units in the application, usually functions, components, or modules. In LobeHub, we use [vitest][vitest-url] for unit testing.
#### Writing Test Cases
Before writing unit tests, you need to create a directory with the same name as the file to be tested and name the test file `<filename>.test.ts`. For example, if you want to test the `src/utils/formatDate.ts` file, the test file should be named `src/utils/formatDate.test.ts`.
In the test file, you can use the `describe` and `it` functions to organize and write test cases. The `describe` function is used to create a test suite, and the `it` function is used to write specific test cases.
```ts
import { formatNumber } from './formatNumber';
describe('formatNumber', () => {
it('should format number with comma separator', () => {
const result = formatNumber(1000);
expect(result).toBe('1,000');
});
it('should return the same number if it is less than 1000', () => {
const result = formatNumber(500);
expect(result).toBe('500');
});
});
```
In test cases, you can use the `expect` function to assert whether the test results meet expectations. The `expect` function can be used with various matchers, such as `toBe`, `toEqual`, `toBeTruthy`, etc.
#### Running Unit Tests
Execute unit tests by running the following command:
```bash
npm run test
```
This will run all unit tests and output the test results.
## Testing Strategy
To write effective test cases, you can consider the following testing strategies:
- **Boundary Testing**: Test the boundary conditions of inputs, such as minimum value, maximum value, empty value, etc.
- **Exception Testing**: Test the code handling exceptional cases, such as error handling, fallback in exceptional situations, etc.
- **Functional Testing**: Test whether various functional modules of the application work properly, including user interaction, data processing, etc.
- **Compatibility Testing**: Test the compatibility of the application on different browsers and devices.
- **Performance Testing**: Test the performance of the application under different loads, such as response time, resource utilization, etc.
Also, ensure that your test cases have good coverage, covering critical code and functionality in the application.
By properly writing and executing unit tests, integration tests, and end-to-end tests, you can improve the quality and stability of the application and promptly identify and fix potential issues.
[vitest-url]: https://vitest.dev/