スキル一覧に戻る
DegrassiAaron

testing

by DegrassiAaron

0🍴 0📅 2025年10月19日
GitHubで見るManusで実行

SKILL.md


name: testing description: Procedures and examples for writing and executing automated tests for software. Use this skill when verifying code correctness with unit, integration, or end-to-end tests. license: MIT allowed-tools:

  • python
  • bash metadata: category: engineering

Testing Guide

Overview

This skill outlines test strategies, frameworks, and code examples to help you ensure your software behaves as expected.

Test Strategy

  1. Unit tests check individual functions or classes.
  2. Integration tests verify that components work together.
  3. End-to-end (E2E) tests simulate user workflows.

Python Testing with pytest

Installing pytest

pip install pytest pytest-cov

Creating a test

Tests are functions that start with test_ in files named test_*.py.

# math_utils.py
def add(a, b):
    return a + b

# test_math_utils.py
from math_utils import add

def test_add():
    assert add(2, 3) == 5

Run tests:

pytest -vv --cov=.

Using fixtures

Fixtures set up test data or state.

import pytest

@pytest.fixture
def sample_data():
    return [1, 2, 3]

def test_length(sample_data):
    assert len(sample_data) == 3

JavaScript Testing with Jest

Installing Jest

npm install --save-dev jest

Creating a test

// sum.js
function sum(a, b) {
  return a + b;
}
module.exports = sum;

// sum.test.js
const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

Add "test": "jest" to the scripts section of package.json and run:

npm test

Test Coverage

Measure code coverage to find untested areas.

For pytest:

pytest --cov=my_package

For Jest:

npm test -- --coverage

Mocking and Patching

Use mocking to isolate components.

from unittest.mock import patch


def test_api_call(monkeypatch):
    def fake_request(url):
        return {"status": 200}
    monkeypatch.setattr(my_module, "make_request", fake_request)
    assert my_module.do_something() == 200

TDD Workflow

  1. Write a failing test that describes desired behavior.
  2. Implement minimal code to pass the test.
  3. Refactor for readability and maintainability.

Use this cycle iteratively to build robust software.

Additional Resources

  • pytest documentation
  • Jest documentation
  • Martin Fowler’s TDD article

スコア

総合スコア

45/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です