搜索

PythonReactSEOPDF
GitHub Skill

testing

Test patterns and commands for LogiAccounting Pro. Use when writing tests, running test suites, or debugging test failures.

Federicojaviermartino☆ 0 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Testing Skill

This skill provides testing patterns and commands.

Quick Commands

Backend (pytest)
cd backend

# Run all tests
pytest

# Run with verbose output
pytest -v

# Run specific file
pytest tests/test_auth.py

# Run specific test
pytest tests/test_auth.py::test_login_success

# Run with coverage
pytest --cov=app --cov-report=html

# Stop on first failure
pytest -x

# Run tests matching pattern
pytest -k "login"
Frontend (Jest)
cd frontend

# Run all tests
npm test

# Run with coverage
npm test -- --coverage

# Run specific file
npm test -- Login.test.jsx

# Watch mode
npm test -- --watch

API Testing with curl

Get Auth Token
# Login as admin
TOKEN=$(curl -s -X POST http://localhost:5000/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"admin@logiaccounting.demo","password":"Demo2024!Admin"}' \
  | jq -r '.token')

echo $TOKEN
Test Endpoints
# GET request
curl -H "Authorization: Bearer $TOKEN" \
  http://localhost:5000/api/v1/inventory/materials

# POST request
curl -X POST http://localhost:5000/api/v1/inventory/materials \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Test Material","reference":"TM-001","quantity":100}'

# PUT request
curl -X PUT http://localhost:5000/api/v1/inventory/materials/ID \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Updated Name"}'

# DELETE request
curl -X DELETE http://localhost:5000/api/v1/inventory/materials/ID \
  -H "Authorization: Bearer $TOKEN"

Test File Template

Backend Test (pytest)
# tests/test_example.py
import pytest
from fastapi.testclient import TestClient
from app.main import app

@pytest.fixture
def client():
    return TestClient(app)

@pytest.fixture
def auth_headers(client):
    response = client.post("/api/v1/auth/login", json={
        "email": "admin@logiaccounting.demo",
        "password": "Demo2024!Admin"
    })
    token = response.json()["token"]
    return {"Authorization": f"Bearer {token}"}

class TestExample:
    def test_get_all(self, client, auth_headers):
        response = client.get("/api/v1/example", headers=auth_headers)
        assert response.status_code == 200
        assert "items" in response.json()

    def test_create(self, client, auth_headers):
        response = client.post(
            "/api/v1/example",
            json={"name": "Test", "value": 100},
            headers=auth_headers
        )
        assert response.status_code == 201

    def test_unauthorized(self, client):
        response = client.get("/api/v1/example")
        assert response.status_code == 401
Frontend Test (Jest + RTL)
// __tests__/Example.test.jsx
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Example from '../pages/Example';

describe('Example Page', () => {
  test('renders loading state', () => {
    render(<Example />);
    expect(screen.getByText(/loading/i)).toBeInTheDocument();
  });

  test('displays data after load', async () => {
    render(<Example />);
    await waitFor(() => {
      expect(screen.getByText(/item name/i)).toBeInTheDocument();
    });
  });

  test('opens modal on button click', async () => {
    render(<Example />);
    await userEvent.click(screen.getByText(/new item/i));
    expect(screen.getByRole('dialog')).toBeInTheDocument();
  });
});

Coverage Goals

Component Target
Auth 90%+
API Routes 80%+
React Pages 70%+
Utils 90%+

CI/CD Integration

# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Backend Tests
        run: |
          cd backend
          pip install -r requirements.txt
          pytest --cov=app
      - name: Frontend Tests
        run: |
          cd frontend
          npm install
          npm test -- --coverage

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!