testing-standards
alibaba/loongcollector/skills/testing-standards/SKILL.md
Testing standards for LoongCollector: unit tests, e2e tests, benchmarks. Reference when writing or reviewing tests.
Skill2.2k starsChanged 3 months ago
What's in it
- LoongCollector Testing Standards
- Test Categories
- 1. Unit Tests (C++)
- 2. Unit Tests (Go)
- 3. E2E Tests
- 4. Benchmarks
- E2E Test Quick Reference
- Feature File Structure
- Behavior Types
- Environment Tags
- Adding New Test Behaviors
- Strict Rules
- Test Naming
- Benchmark Testing
---
name: testing-standards
description: Testing standards for LoongCollector: unit tests, e2e tests, benchmarks. Reference when writing or reviewing tests.
---
# LoongCollector Testing Standards
## Test Categories
### 1. Unit Tests (C++)
- Use Google Test (GTest) / Google Mock
- Place in `core/unittest/`
- Cover success and failure paths
- Core logic must have 100% coverage
- Test boundary conditions explicitly
- Test naming: accurately describe behavior being tested
- Each `core/unittest/*/` directory produces one executable
- Build and run tests from inside `build/` to ensure relative paths and temp files work correctly
- See `skills/compile/SKILL.md` for build & run instructions
### 2. Unit Tests (Go)
- Use standard `testing` package
- Table-driven tests for function coverage
- Integration tests via E2E framework
### 3. E2E Tests
- BDD Godog framework
- Configuration-driven via `.feature` files
- See `skills/e2e/SKILL.md` for complete guide (design → write → run → debug)
### 4. Benchmarks
- Required for performance-sensitive code paths
- Compare against baseline versions
- Measure throughput, latency, CPU/Memory usage
## E2E Test Quick Reference
### Feature File Structure
```
@input
Feature: input file
Test input file
@e2e @host
Scenario: TestInputFileWithRegexSingle
Given {host} environment
Given subcribe data from {sls} with config
"""
enable: true
inputs:
- Type: input_file
"""
When generate {100} regex logs to file {/tmp/loongcollector/regex_single.log}, with interval {100}ms
Then there is {100} logs
```
### Behavior Types
| Type | Purpose |
|------|---------|
| `Given` | Setup/prepare test conditions |
| `When` | Trigger test actions (e.g., log generation) |
| `Then` | Verify test results |
### Environment Tags
- `@host` - Host environment
- `@k8s` - Kubernetes environment
- `@docker-compose` - Docker Compose environment
- `@e2e` - E2E test marker
- `@regression` - Regression test marker
### Adding New Test Behaviors
1. Write the Go function in the appropriate directory:
- `cleanup/` - Post-test cleanup (auto-executed)
- `control/` - Control operations (init, config)
- `setup/` - Environment setup
- `trigger/` - Data generation
- `verify/` - Result verification
2. Function signature: `func Name(ctx context.Context, params...) (context.Context, error)`
3. Register in `test/e2e_enterprise/main_test.go` via `scenarioInitializer`
4. Use in feature files with `{param}` syntax
### Strict Rules
- Do NOT change behavior of the method being tested
- Do NOT modify existing test behaviors in engine
- Always start trigger `When begin trigger` BEFORE generating logs
- Only use registered behaviors from `test/engine/steps.go`
- Verify behavior type matches (Given/When/Then)
### Test Naming
- Format: `Test${FunctionName}${CaseBriefDescription}`
- Examples: `TestInputFileWithBlackListDir`, `TestInputFileWithRegexSingle`
- Must include `@e2e` and environment tags
## Benchmark Testing
For performance-sensitive code:
1. Provide baseline comparison
2. Measure: throughput, latency, CPU profile, memory profile
3. Run under realistic load conditions
4. Document methodology and results
More agent context in alibaba/loongcollector
35 other files this repository gives its agents.
AGENTS.md
CLAUDE.md
Copilot instructions
Cursor rule
- .cursor/rules/coding-standards/commit.mdc
- .cursor/rules/coding-standards/compile.mdc
- .cursor/rules/coding-standards/cpp.mdc
- .cursor/rules/coding-standards/golang.mdc
- .cursor/rules/project-knowledge/architecture.md
- .cursor/rules/project-knowledge/architecture.mdc
- .cursor/rules/project-knowledge/codebase-map.md
- .cursor/rules/project-knowledge/config-pitfalls.mdc
- .cursor/rules/project-knowledge/terminology.mdc
- .cursor/rules/README
- .cursor/rules/review-standards/code-review.md
- .cursor/rules/review-standards/code-review.mdc
- .cursor/rules/testing-standards/e2e-develop-guide.mdc
- .cursor/rules/testing-standards/e2e-example-ebpf-process.mdc
- .cursor/rules/testing-standards/e2e-manual.mdc
- .cursor/rules/utils/mermaid.mdc
- .cursor/rules/workflows/design-document.mdc
- .cursor/rules/workflows/riper5-protocol.mdc
Skill
- code-reviewskills/code-review/SKILL.md
- commitskills/commit/SKILL.md
- compileskills/compile/SKILL.md
- design-documentskills/design-document/SKILL.md
- e2e-develop-guideskills/e2e-develop-guide/SKILL.md
- e2e-manualskills/e2e-manual/SKILL.md
- e2eskills/e2e/SKILL.md
- mermaidskills/mermaid/SKILL.md
- omc-referenceskills/omc-reference/SKILL.md
- project-knowledgeskills/project-knowledge/SKILL.md
- review-standardsskills/review-standards/SKILL.md
- riper5-protocolskills/riper5-protocol/SKILL.md
- security-checkskills/security-check/SKILL.md
- selfmonitorskills/selfmonitor/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

