README.md 1.6 KB
Newer Older
1
2
# Run Unit Tests

3
SGLang uses the built-in library [unittest](https://docs.python.org/3/library/unittest.html) as the testing framework.
Lianmin Zheng's avatar
Lianmin Zheng committed
4
5
6
7

## Test Backend Runtime
```bash
cd sglang/test/srt
8
9

# Run a single file
Lianmin Zheng's avatar
Lianmin Zheng committed
10
python3 test_srt_endpoint.py
11

Lianmin Zheng's avatar
Lianmin Zheng committed
12
13
14
15
# Run a single test
python3 -m unittest test_srt_endpoint.TestSRTEndpoint.test_simple_decode

# Run a suite with multiple files
16
17
18
python3 run_suite.py --suite minimal
```

Lianmin Zheng's avatar
Lianmin Zheng committed
19
20
21
22
## Test Frontend Language
```bash
cd sglang/test/lang
export OPENAI_API_KEY=sk-*****
23
24

# Run a single file
Lianmin Zheng's avatar
Lianmin Zheng committed
25
26
27
28
python3 test_openai_backend.py

# Run a single test
python3 -m unittest test_openai_backend.TestOpenAIBackend.test_few_shot_qa
29

Lianmin Zheng's avatar
Lianmin Zheng committed
30
# Run a suite with multiple files
31
32
python3 run_suite.py --suite minimal
```
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

## Adding or Updating Tests in CI

- Create new test files under `test/srt` or `test/lang` depending on the type of test.
- Ensure they are referenced in the respective `run_suite.py` (e.g., `test/srt/run_suite.py` or `test/lang/run_suite.py`) so they’re picked up in CI.
- In CI, all tests run automatically. You may modify the workflows in [`.github/workflows/`](https://github.com/sgl-project/sglang/tree/main/.github/workflows) to add custom test groups or extra checks.


## 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.