页面加载中...
为你的 Skill 建立单元测试、集成测试和端到端测试,确保每次更新不引入回归。
Skill 是 AI 的能力单元。一个有 bug 的 Skill = AI 在关键时刻掉链子。
测试金字塔:
测试 Skill 的核心函数,不依赖外部服务:
import { parseWeatherResponse } from '../scripts/parser.js'; test('解析正常天气响应', () => { const result = parseWeatherResponse({ temp: 22, status: 'sunny' }); expect(result.summary).toContain('22°C'); expect(result.isGoodForOutdoor).toBe(true); }); test('处理空数据', () => { expect(() => parseWeatherResponse(null)).toThrow('无效天气数据'); });
测试 Skill 与外部 API 的交互,使用 mock:
test('调用天气 API 并格式化结果', async () => { const mockFetch = jest.fn().mockResolvedValue({ json: () => Promise.resolve({ temp: 18, status: 'cloudy' }) }); global.fetch = mockFetch; const result = await getWeather('Shanghai'); expect(mockFetch).toHaveBeenCalled(); expect(result).toContain('18°C'); });
on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm test
Agent 站点首选部署平台,零配置部署 Next.js,全球 CDN
立即体验 →