2024-08-03 23:09:21 -07:00
# Run Unit Tests
2024-11-06 21:46:04 +08:00
SGLang uses the built-in library [unittest ](https://docs.python.org/3/library/unittest.html ) as the testing framework.
2024-08-10 15:09:03 -07:00
## Test Backend Runtime
```bash
cd sglang/test/srt
2024-08-03 23:09:21 -07:00
# Run a single file
2024-08-10 15:09:03 -07:00
python3 test_srt_endpoint.py
2024-08-03 23:09:21 -07:00
2024-08-10 15:09:03 -07:00
# Run a single test
python3 -m unittest test_srt_endpoint.TestSRTEndpoint.test_simple_decode
# Run a suite with multiple files
2025-01-02 18:25:26 -08:00
python3 run_suite.py --suite per-commit
2024-08-03 23:09:21 -07:00
```
2024-08-10 15:09:03 -07:00
## Test Frontend Language
```bash
cd sglang/test/lang
2024-08-03 23:09:21 -07:00
# Run a single file
2025-08-10 19:49:45 -07:00
python3 test_srt_backend.py
2024-08-03 23:09:21 -07:00
```
2025-01-02 17:18:31 +00:00
## Adding or Updating Tests in CI
- Create new test files under `test/srt` or `test/lang` depending on the type of test.
2025-08-10 19:49:45 -07:00
- Ensure they are referenced in the respective `run_suite.py` (e.g., `test/srt/run_suite.py` ) so they’ re picked up in CI. For most small test cases, they can be added to the `per-commit` suite. Sort the test cases alphabetically.
2025-01-02 18:25:26 -08:00
- The CI will run the `per-commit` and `nightly` automatically. If you need special setup or custom test groups, you may modify the workflows in [`.github/workflows/` ](https://github.com/sgl-project/sglang/tree/main/.github/workflows ).
2025-01-02 17:18:31 +00:00
## Writing Elegant Test Cases
- Examine existing tests in [sglang/test ](https://github.com/sgl-project/sglang/tree/main/test ) for practical examples.
- Keep each test function focused on a single scenario or piece of functionality.
- Give tests descriptive names reflecting their purpose.
- Use robust assertions (e.g., assert, unittest methods) to validate outcomes.
- Clean up resources to avoid side effects and preserve test independence.
2025-08-10 19:49:45 -07:00
- Reduce the test time by using smaller models and reusing the server for multiple test cases.