Logo Debugging Testing

Debugging Testing

Cộng đồng
Tibsfox
debugging-testing

Use when the user reports a bug they can't reproduce, asks where to start debugging, or mentions a Heisenbug / production-only failure. Drives the observe→hypothesize→predict→test→iterate scientific method.

Tổng quan

Nhà phát hànhTibsfox
Kho mãgsd-skill-creator
Tên kỹ năngdebugging-testing
Sao
70
Bản fork
9
Tệp đi kèm
1
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 1 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được Tibsfox công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Debugging Testing trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/Tibsfox/gsd-skill-creator/tree/main/examples/skills/coding/debugging-testing
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Tibsfox/gsd-skill-creator.git /tmp/gsd-skill-creator
mkdir -p .claude/skills
cp -r /tmp/gsd-skill-creator/examples/skills/coding/debugging-testing .claude/skills/debugging-testing
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Debugging Testing trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Debugging Testing ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Debugging Testing không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Debugging & Testing

A program without tests is a hypothesis. A program with bugs and no debugging strategy is a mystery. This skill catalogs systematic approaches to both: finding defects (debugging) and preventing them (testing). The emphasis is on method over intuition -- debugging and testing are engineering disciplines with established techniques, not arts that depend on talent.

Agent affinity: hopper (coined "debugging" when she found a moth in the Mark II), dijkstra (program correctness as a mathematical property)

Concept IDs: code-debugging-strategies, code-iterative-development, code-peer-review

Part 1 -- The Debugging Mindset

Debugging as Scientific Method

A bug is a hypothesis falsifier: your mental model of the program says X should happen, but Y happens instead. Debugging is the process of updating your mental model until it matches reality.

  1. Observe the symptom. What actually happened? What did you expect?
  2. Hypothesize. What could cause the discrepancy? List at least three candidates.
  3. Predict. If hypothesis H is true, what would happen if I do experiment E?
  4. Test. Perform the experiment. Does the result match the prediction?
  5. Iterate. If the prediction was wrong, the hypothesis is eliminated. Try the next one.

This is the scientific method applied to code. The most common debugging mistake is skipping step 2 -- changing things at random hoping the bug disappears. Random changes do not build understanding. They may mask the bug or introduce new ones.

Grace Hopper's Debugging Legacy

In 1947, operators of the Harvard Mark II found a moth trapped in a relay, causing a malfunction. Grace Hopper taped the moth into the logbook with the note "First actual case of bug being found." The term "debugging" predates this incident, but Hopper's story crystallized the concept: finding and removing defects is a first-class engineering activity, not a sign of failure.

Hopper's broader contribution to debugging was the invention of the compiler. Before compilers, programs were written in machine code, and every error was a numerical one. Compilers introduced symbolic names, structured control flow, and -- critically -- error messages. The compiler was the first automated debugging tool.

Part 2 -- Debugging Techniques

2.1 -- Printf / Logging Debugging

Technique: Insert print statements or log calls at strategic points to observe the program's state as it executes.

When to use. First response for any bug. Fast to deploy, works in any language, requires no special tools. Especially valuable in environments where interactive debuggers are impractical (distributed systems, embedded systems, CI pipelines).

Best practices.

  • Log the function name, key variable values, and the decision path taken.
  • Use structured logging (JSON) for production systems so logs are searchable.
  • Remove or disable debug prints before committing. Use log levels (DEBUG, INFO, WARN, ERROR) to control verbosity without removing code.

Limitation. Heisenbug risk: adding print statements can change timing, which may mask concurrency bugs.

2.2 -- Interactive Debuggers

Technique: Pause execution at breakpoints, inspect variables, step through code line by line.

Tools. GDB (C/C++), LLDB (C/C++/Rust), pdb (Python), Chrome DevTools (JavaScript), VS Code debugger (multi-language).

Key operations.

  • Breakpoint: Pause when execution reaches a specific line.
  • Conditional breakpoint: Pause only when a condition is true (e.g., i == 999).
  • Watch expression: Monitor a variable and pause when its value changes.
  • Step over: Execute the current line, skip into function calls.
  • Step into: Enter the function being called.
  • Step out: Execute until the current function returns.

When to use. Complex control flow where printf would require dozens of statements. Inspecting data structures that are hard to print (circular references, large trees). Understanding unfamiliar code.

2.3 -- Binary Search Debugging

Technique: Narrow the problem to the smallest possible scope by halving the search space at each step.

Application to time. If a bug appeared recently, use git bisect to binary-search through commits: mark a known-good commit and a known-bad commit, test the midpoint, repeat. In O(log n) steps, find the exact commit that introduced the bug.

Application to code. Comment out half the code. Does the bug persist? If yes, the bug is in the remaining half. If no, the bug is in the commented half. Repeat.

Application to data. If the bug occurs with a large input, halve the input. Does the bug persist? Binary search to find the minimal reproducing input.

2.4 -- Rubber Duck Debugging

Technique: Explain the code, line by line, to an inanimate object (traditionally a rubber duck). The act of articulating your assumptions often reveals the one that is wrong.

Why it works. Reading code silently allows your brain to skip over details. Speaking forces you to process each line consciously. The mismatch between what you say and what the code does surfaces the bug.

Formal variant. Code review. Explaining your code to a colleague achieves the same effect with the added benefit of a second perspective.

2.5 -- Time-Travel Debugging

Technique: Record program execution and replay it, stepping backward and forward through time.

Tools. rr (Linux, C/C++/Rust), Replay.io (JavaScript), IntelliJ's step-back feature.

When to use. Concurrency bugs, non-deterministic failures, bugs that are hard to reproduce. Time-travel debugging eliminates the need to reproduce the bug -- you debug the exact execution that failed.

2.6 -- Git Bisect

Technique: Automated binary search through git history to find the commit that introduced a bug.

Usage.

git bisect start
git bisect bad              # Current commit has the bug
git bisect good abc1234     # This commit was known-good
# Git checks out the midpoint. Test it.
git bisect good             # or: git bisect bad
# Repeat until the first bad commit is found.
git bisect reset            # Return to original state

Automation. git bisect run ./test.sh -- provide a script that returns 0 for good and non-zero for bad. Git runs the binary search automatically.

Prerequisite. Each commit must be independently testable. This is one reason to keep commits small and atomic.

Part 3 -- Testing Levels

3.1 -- Unit Tests

Scope: Test a single function, method, or class in isolation.

Characteristics. Fast (milliseconds per test), deterministic (no I/O, no network, no database), focused (one assertion per logical concept).

Isolation techniques. Mocks (simulate dependencies), stubs (provide canned answers), fakes (simplified implementations, e.g., in-memory database).

When to use. Every pure function. Every method with business logic. The foundation of the test pyramid.

3.2 -- Integration Tests

Scope: Test the interaction between two or more components (e.g., service + database, API + authentication).

Characteristics. Slower than unit tests, may require real infrastructure (database, message queue), tests contracts between components.

When to use. Validating that the database layer correctly persists and retrieves data. Ensuring that API endpoints handle real HTTP requests. Testing message serialization/deserialization across service boundaries.

3.3 -- End-to-End Tests

Scope: Test the entire system from the user's perspective. UI clicks through backend to database and back.

Characteristics. Slowest, most brittle (sensitive to UI changes, timing, environment), most realistic.

Tools. Playwright, Cypress, Selenium (web), Appium (mobile).

When to use. Sparingly. Cover the critical user journeys (signup, purchase, core workflow). Too many E2E tests create a slow, flaky test suite that developers learn to ignore.

3.4 -- Acceptance Tests

Scope: Verify that the system meets the business requirements as specified by stakeholders.

Relationship to levels. Acceptance tests can run at any level (unit, integration, E2E) depending on what is being verified. They are defined by intent (does the system do what the business needs?) rather than technique.

The Test Pyramid

        /  E2E  \           Few, slow, brittle
       /----------\
      / Integration \       Some, medium speed
     /----------------\
    /    Unit Tests    \    Many, fast, focused

Invert the pyramid (many E2E, few units) and you get a slow, fragile, expensive test suite. The pyramid structure maximizes confidence per test-dollar.

Part 4 -- Test-Driven Development (TDD)

The Red-Green-Refactor Cycle

  1. Red. Write a test for the next piece of functionality. Run it. It fails (because the functionality does not exist yet).
  2. Green. Write the minimum code to make the test pass. No more.
  3. Refactor. Clean up the code while keeping all tests green. Improve names, extract functions, remove duplication.

Repeat. Each cycle takes minutes, not hours. The test suite grows with the code, providing continuous regression protection.

Why TDD Works

  • Design pressure. Writing the test first forces you to think about the interface before the implementation. Hard-to-test code is usually hard-to-test because it is badly designed -- tight coupling, hidden dependencies, side effects. TDD makes these problems visible immediately.
  • Regression safety. Every feature has tests from the moment it is written. Refactoring is safe because the tests catch regressions instantly.
  • Documentation. Tests are executable documentation. They show how the code is intended to be used.

When TDD Hurts

  • Exploratory work. When you do not know what the interface should look like, writing tests first anchors you to a premature design. Spike first, then test.
  • UI code. Rapidly changing UIs make tests brittle. Test the logic behind the UI, not the pixel positions.
  • Integration with external systems. When the behavior depends on a third-party API you do not control, TDD requires extensive mocking that may not reflect real behavior.

Part 5 -- Test Design Techniques

5.1 -- Equivalence Partitioning

Technique: Divide the input space into classes where the program should behave identically. Test one representative from each class.

Example. A function that grades scores 0-100: F (0-59), D (60-69), C (70-79), B (80-89), A (90-100). Test one value from each partition: 45, 65, 75, 85, 95.

5.2 -- Boundary Value Analysis

Technique: Test at the edges of equivalence partitions, where off-by-one errors concentrate.

Example. For the grading function above: 0, 59, 60, 69, 70, 79, 80, 89, 90, 100. Also test just outside the valid range: -1, 101.

5.3 -- Property-Based Testing

Technique: Instead of specifying individual test cases, specify properties that must hold for all inputs. The testing framework generates hundreds or thousands of random inputs and checks the property.

Tools. Hypothesis (Python), fast-check (JavaScript/TypeScript), QuickCheck (Haskell, original), proptest (Rust).

Example properties.

  • sort(list) has the same length as list.
  • sort(list) contains the same elements as list.
  • sort(list) is non-decreasing.
  • reverse(reverse(list)) == list.
  • parse(serialize(obj)) == obj (round-trip).

Shrinking. When a failing input is found, the framework automatically simplifies it to the minimal reproducing case. This is enormously valuable for debugging.

5.4 -- Mutation Testing

Technique: Automatically introduce small changes (mutations) to the code -- change + to -, flip < to <=, delete a line. If the test suite still passes, it has a gap: the mutant "survived." Kill rate measures test suite thoroughness.

Tools. Stryker (JavaScript/TypeScript), mutmut (Python), pitest (Java).

Interpretation. A high kill rate (>80%) indicates thorough testing. Surviving mutants reveal specific untested behaviors.

Part 6 -- Profiling and Performance Debugging

CPU Profiling

Sampling profiler. Periodically records which function is executing. Low overhead, statistical accuracy. Identifies hot functions (where most time is spent).

Instrumentation profiler. Records entry and exit of every function. High overhead, exact counts. Identifies call frequency and per-call duration.

Tools. perf (Linux), Instruments (macOS), py-spy (Python), clinic.js (Node.js), cargo-flamegraph (Rust).

Memory Profiling

Heap profiling. Track allocations, find memory leaks (objects that grow without bound), identify excessive allocation churn.

Tools. Valgrind/Massif (C/C++), tracemalloc (Python), Chrome DevTools heap snapshot (JavaScript), DHAT (Rust via Valgrind).

Flame Graphs

Visualization. A flame graph shows the call stack with width proportional to time spent. Wide bars at the top are the hot functions. The shape reveals whether the time is spent in one deep call chain or spread across many.

Reading a flame graph. The x-axis is NOT time -- it is the alphabetical sort of stack frames at each depth. Width is the cumulative time. Look for wide plateaus (optimization targets) and unexpected width (functions that should be fast but are not).

Debugging Strategy Selection

SymptomFirst techniqueWhy
Wrong output, simple functionPrintf + unit testFast feedback, isolate the logic
Wrong output, complex flowInteractive debuggerStep through the decision path
Recent regressionGit bisectFind the exact commit
Intermittent failureLogging + time-travel debugCapture the non-deterministic execution
Performance degradationCPU profiler + flame graphIdentify the hot path
Memory growthHeap profilerFind the leak
Concurrency bugThread sanitizer + rrDetect races, replay exact execution
"It works on my machine"Environment diff + integration testIsolate the environmental dependency

Common Mistakes

MistakeWhy it failsFix
Testing implementation, not behaviorTests break on refactoringTest the public interface, not internal details
100% code coverage as a goalCoverage measures lines executed, not correctnessAim for meaningful coverage of behavior, not line count
Flaky tests left unfixedTeam learns to ignore test failuresFix or delete flaky tests immediately
No test isolationTests depend on each other's stateEach test sets up and tears down its own state
Debugging by random changesNo understanding of the bugApply the scientific method: hypothesize, predict, test
Skipping the minimal reproductionDebugging a complex system when the bug is in one functionReduce to the smallest failing case before debugging
Over-mockingTests pass but code fails in productionUse integration tests for interaction boundaries

Cross-References

  • hopper agent: Debugging heritage, compiler as debugging tool, practical language implementation.
  • dijkstra agent: Program correctness proofs, structured programming as bug prevention.
  • papert agent: Teaching debugging as a learning skill, not a punishment.
  • knuth agent: Literate programming as a debugging aid -- code that is clear enough to read is easier to debug.
  • programming-fundamentals skill: The constructs being debugged and tested.
  • software-design skill: Design principles that make code testable.

References

  • Hopper, G. M. (1947). Mark II logbook entry. Naval Surface Warfare Center, Dahlgren, VA.
  • Zeller, A. (2009). Why Programs Fail. 2nd edition. Morgan Kaufmann.
  • Beck, K. (2002). Test-Driven Development: By Example. Addison-Wesley.
  • Meszaros, G. (2007). xUnit Test Patterns. Addison-Wesley.
  • Claessen, K. & Hughes, J. (2000). "QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs." ICFP 2000.
  • Gregg, B. (2020). Systems Performance: Enterprise and the Cloud. 2nd edition. Addison-Wesley.
  • O'Callahan, R. et al. (2017). "Engineering Record And Replay For Deployability." USENIX ATC 2017.

Tệp đi kèm

Mô hình đọc các tệp này khi cần trong lúc kỹ năng được tải. Các tệp được cung cấp ở dạng có thể đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Debugging Testing làm được gì?

Use when the user reports a bug they can't reproduce, asks where to start debugging, or mentions a Heisenbug / production-only failure. Drives the observe→hypothesize→predict→test→iterate scientific method.

Vì sao nên dùng Debugging Testing trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Debugging Testing là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Debugging Testing trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/Tibsfox/gsd-skill-creator/tree/main/examples/skills/coding/debugging-testing. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Debugging Testing?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Debugging Testing với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Debugging Testing với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Debugging Testing có miễn phí không?

Kỹ năng này được Tibsfox phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇