Evaluating LLM Coding Ability in Real-World Scenarios: A Deep Dive into Four Practical Tasks

    This article presents a practical evaluation of large language models for coding, moving beyond public leaderboards to four real-world scenarios: large codebase comprehension, cross-file refactoring, production bug fixing, and unit test generation. For each scenario, it defines the task, lists evaluation criteria, and offers implementation tips, followed by a four-dimension scoring system and a rollout path for building a repeatable internal evaluation pipeline.

    1. Why Real-World Scenarios Beat Leaderboards

    As AI coding tools iterate quickly, the key question for developers has shifted from “Can the model write code?” to “Can the model deliver reliably inside my project?” Public leaderboards typically use well-structured, self-contained problem sets. A high score does not mean the model is usable in a real repository. Real projects usually have three traits: noisy context, constraints embedded in existing code, and a high cost of errors. Evaluation design should therefore shift from “problem accuracy” to “task completion.”

    A reusable approach is to select four types of tasks that genuinely occur in daily work, keep the input context budget, prompt template, and acceptance criteria consistent, and run multiple rounds to observe stability. The four scenarios are described below.

    2. Scenario 1: Understanding and Q&A on a Large Codebase

    Task setup: Given a project directory with tens of thousands of lines, the model must answer questions about module responsibilities, call chains, key data structures, and extension points.

    Evaluation criteria:

    • Location accuracy: Does it point to the correct files and function entry points instead of giving vague answers?
    • Call chain completeness: Does it miss key branches and callback paths?
    • Traceable evidence: Are conclusions backed by code references?
    • Hallucination rate: Does it invent interfaces or configuration items that do not exist?

    Practical tip: Do not stuff the entire source code into the context at once. Use a layered context strategy of “retrieve, summarize, then answer.” A sample flow:

    1. repo index -> keyword/symbol search -> candidate snippet trimming -> structured summary -> targeted Q&A -> citation verification

    The scenario passes only when the model’s output can consistently map to specific symbol locations.

    3. Scenario 2: Cross-File Refactoring with Constraint Preservation

    Task setup: Complete cross-module renaming, interface extraction, and duplicate logic consolidation without changing external behavior.

    Evaluation criteria:

    • Change scope control: Does it modify only the necessary files?
    • Compatibility: Are callers updated accordingly?
    • Regression risk: Does it introduce implicit dependencies?
    • Rollback capability: Can the changes be split into small commits?

    Break refactoring into four steps: dependency analysis, change plan, incremental execution, and verification. Require the model to output a plan before changing code. For high-risk changes, combine small-batch commits with an automated verification pipeline (such as static checks, unit tests, and build verification) as a safety net.

    4. Scenario 3: Locating and Fixing Production Bugs

    Task setup: Provide the error stack, reproduction steps, and relevant code snippets, and ask for a root-cause hypothesis and a minimal fix.

    Evaluation criteria:

    • Hypothesis quality: Does it provide verifiable root-cause candidates instead of piling up possibilities?
    • Minimal change: Is the fix restrained, avoiding opportunistic rewrites?
    • Observability: Does it add logs, metrics, or assertions?
    • Regression coverage: Does it add targeted test cases?

    Have the model output a structured conclusion in five parts: symptom, hypothesis, verification method, fix patch, and regression test. This makes review easier and helps turn effective practices into team standards.

    5. Scenario 4: Unit Test and Boundary Case Generation

    Task setup: Generate tests for a given function that cover normal paths, boundary conditions, and exception paths.

    Evaluation criteria:

    • Whether coverage improvement is real;
    • Whether assertions are effective, avoiding “run without asserting”;
    • Whether unstable factors such as time, randomness, and external dependencies are handled;
    • Test readability and maintenance cost.

    Use the following pseudocode to constrain the output structure:

    1. def test_case(name, arrange, act, assert_rule):
    2. # arrange: set up inputs and test doubles for dependencies
    3. # act: call the unit under test
    4. # assert_rule: a clearly decidable assertion
    5. ...

    6. Scoring System and Implementation Advice

    Use a four-dimension weighted score: functional correctness, adherence to engineering constraints, stability (consistency across multiple rounds), and collaboration cost (review and rework time). Adjust the weights based on the team’s risk preference; for example, increase the weight on constraint adherence in high-compliance scenarios.

    For rollout, start with low-risk tasks, build an internal evaluation set and regression baseline, and then combine container platforms, logging services, and monitoring and alerting capabilities from general cloud services such as Baidu AI Cloud to engineer the evaluation pipeline, achieving version traceability, reproducible results, and measurable quality.