← 返回
未分类 中文

Test Runner

Write and run tests across languages and frameworks.
跨语言和框架编写并运行测试
alexwoo-awso alexwoo-awso 来源
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 451
下载
💾 1
安装
1
版本
#latest

概述

Test Runner

Core workflow

  1. Detect the language, package manager, and existing test framework before changing anything.
  2. Prefer the project's current test stack over introducing a new one.
  3. Run the smallest relevant test scope first, then widen coverage after the failure is understood.
  4. When fixing bugs, start with a failing test, make the smallest code change that passes, then refactor.
  5. After changes, run the narrow test again and then a broader suite if the local workflow supports it.

Framework selection

Use the existing framework when one is already configured. If the project has no test stack, prefer:

LanguageUnit testsIntegrationEnd-to-end
------------
TypeScript / JavaScriptVitestSupertestPlaywright
Pythonpytestpytest + httpxPlaywright
SwiftXCTestXCTestXCUITest

Command guide

Vitest

npm install -D vitest @testing-library/react @testing-library/jest-dom
npx vitest
npx vitest run
npx vitest --coverage

Use this baseline config when a project needs one:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: './tests/setup.ts',
  },
})

Jest

npm install -D jest @types/jest ts-jest
npx jest
npx jest --watch
npx jest --coverage
npx jest path/to/test

pytest

uv pip install pytest pytest-cov pytest-asyncio httpx
pytest
pytest -v
pytest -x
pytest --cov=app
pytest tests/test_api.py -k "test_login"
pytest --tb=short

XCTest

swift test
swift test --filter MyTests
swift test --parallel

Playwright

npm install -D @playwright/test
npx playwright install
npx playwright test
npx playwright test --headed
npx playwright test --debug
npx playwright test --project=chromium
npx playwright show-report

Red-green-refactor

  1. Red: write a failing test for the behavior you need.
  2. Green: implement the smallest change that makes it pass.
  3. Refactor: clean up without changing behavior.

Test patterns

Arrange, act, assert

test('calculates total with tax', () => {
  const cart = new Cart([{ price: 100, qty: 2 }])

  const total = cart.totalWithTax(0.08)

  expect(total).toBe(216)
})

Async tests

test('fetches user data', async () => {
  const user = await getUser('123')
  expect(user.name).toBe('Colt')
})

Mocking with Vitest

import { vi } from 'vitest'

const mockFetch = vi.fn().mockResolvedValue({
  json: () => Promise.resolve({ id: 1, name: 'Test' }),
})

vi.stubGlobal('fetch', mockFetch)

API tests in Python

import pytest
from httpx import AsyncClient
from app.main import app


@pytest.mark.asyncio
async def test_get_users():
    async with AsyncClient(app=app, base_url="http://test") as client:
        response = await client.get("/users")

    assert response.status_code == 200
    assert isinstance(response.json(), list)

React component tests

import { fireEvent, render, screen } from '@testing-library/react'
import { Button } from './Button'

test('calls onClick when clicked', () => {
  const handleClick = vi.fn()
  render(<Button onClick={handleClick}>Click me</Button>)
  fireEvent.click(screen.getByText('Click me'))
  expect(handleClick).toHaveBeenCalledOnce()
})

Coverage commands

# JavaScript / TypeScript
npx vitest --coverage
npx jest --coverage

# Python
pytest --cov=app --cov-report=html
pytest --cov=app --cov-report=term
pytest --cov=app --cov-fail-under=80

What to test

Always test:

  • Public APIs and exported functions
  • Edge cases such as empty input, null, and boundary values
  • Error handling such as invalid input or network failures
  • Business logic such as calculations and state transitions

Usually skip:

  • Private implementation details
  • Framework internals
  • Trivial getters and setters
  • Third-party library behavior

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-03 06:51 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 689 📥 332,628
dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 200 📥 68,558
professional

KSeF Accountant (Polish)

alexwoo-awso
{"answer":"波兰语KSeF会计助理。适用于KSeF 2.0 API、FA(3)发票、波兰VAT合规、电子发票处理、付款匹配、VAT登记(JPK_V7)、红字发票、分账支付机制(MPP)及波兰会计流程。在KSeF生态系统中提供发票开
★ 0 📥 2,340