Evaluating Large Language Model Coding Ability: A Reusable Testing Method

    A systematic evaluation framework for AI coding models, covering task design, success criteria, scoring dimensions, automated testing, bias control, and practical adoption in engineering teams. The approach helps teams replace subjective impressions with reproducible data when selecting models and defining safe usage boundaries.

    1. Why Systematic Evaluation Matters

    Over the past few years, large language models have been widely used for code generation, defect localization, unit test completion, and code review. Yet the same model can receive very different feedback from different teams. Some developers find that its generated functions can be merged directly, while others find that it frequently invents nonexistent APIs. These conclusions are often based on scattered experiences, small samples, and inconsistent scenarios, making them difficult to compare.

    Systematic evaluation addresses this problem by using consistent inputs, consistent criteria, and a repeatable process within a clearly defined task scope. The goal is to answer a practical question: Which tasks can the model complete in our business context, and how does it fail when it cannot?

    2. Define the Evaluation Goals First

    Before starting an evaluation, clarify three aspects.

    Use Cases

    Determine how the team intends to use the model. Is the goal to generate boilerplate code, perform cross-file refactoring, or create test cases? Different scenarios place different demands on context length, reasoning depth, and output format. The evaluation tasks should reflect those requirements.

    Success Criteria

    Define measurable criteria for success. For example, generated code may need to pass the existing unit tests, introduce no new static-analysis warnings, and avoid undeclared dependencies. Success criteria should be machine-verifiable whenever possible. Otherwise, results may be influenced by the subjective preferences of individual reviewers.

    Acceptable Failure Modes

    Consider which types of failure are most concerning. Is an explicit error more acceptable than code that appears reasonable but contains a subtle logical defect? For most teams, the latter presents a greater risk because it is harder to detect. Evaluations should track these hidden errors separately.

    3. Build the Task Set

    The task set is the foundation of the evaluation. Whenever possible, extract samples from real tickets, historical defects, and code review records instead of creating all tasks manually.

    Each task should include at least five fields:

    • Task description
    • Input context
    • Reference implementation or test cases
    • Difficulty level
    • Task category

    Difficulty can be divided into three levels:

    • Basic: Single-function implementations and simple string processing
    • Intermediate: Coordination between multiple functions or comprehension of an existing module
    • Advanced: Cross-module changes, concurrency logic, and compatibility handling

    The three levels should contain approximately equal numbers of samples. Otherwise, an evaluation dominated by simple tasks may inflate the average score and hide important weaknesses.

    For sample size, prepare at least 20 to 30 tasks for each category. With too few samples, random variation in a single run can significantly change the conclusions.

    4. Design the Scoring Dimensions

    A single pass rate does not adequately reflect code quality. At a minimum, evaluate the following four dimensions:

    Functional Correctness

    Does the generated code pass all test cases? This is a hard gate. Samples that fail the functional tests should not receive scores in the other dimensions.

    Code Quality

    Does the code follow the team’s naming conventions, structural guidelines, and static-analysis rules?

    Security

    Does the code introduce common issues such as injection risks, hard-coded credentials, or unauthorized access?

    Maintainability

    Is the scope of the change appropriately limited? Does it introduce unnecessary abstraction layers?

    Each dimension can be scored from 0 to 2. For failed samples, also record reason labels such as:

    • Invented API
    • Missed edge case
    • Invalid output format

    These labels help the team identify systematic weaknesses instead of only producing an average score.

    5. Automate the Evaluation Process

    The following example illustrates the structure of an evaluation framework. The model-calling function is intentionally left as an interface so that each team can connect its preferred service. Because model output is untrusted content, generated code should be executed in an isolated sandbox in real projects.

    1. import json
    2. import subprocess
    3. def call_model(prompt: str) -> str:
    4. # Implement this function to wrap the selected model service
    5. raise NotImplementedError
    6. def run_tests(workdir: str) -> bool:
    7. # Pass arguments as a list to avoid shell parsing of external content
    8. result = subprocess.run(
    9. ["pytest", "-q"],
    10. cwd=workdir,
    11. capture_output=True,
    12. text=True,
    13. timeout=120,
    14. )
    15. return result.returncode == 0
    16. def evaluate(tasks_path: str, out_path: str) -> None:
    17. with open(tasks_path, encoding="utf-8") as f:
    18. tasks = json.load(f)
    19. records = []
    20. for task in tasks:
    21. prompt = build_prompt(task) # Build the prompt from a fixed template
    22. answer = call_model(prompt)
    23. workdir = materialize(task, answer) # Write the output to a temporary work directory
    24. passed = run_tests(workdir)
    25. records.append({
    26. "id": task["id"],
    27. "level": task["level"],
    28. "passed": passed,
    29. })
    30. with open(out_path, "w", encoding="utf-8") as f:
    31. json.dump(records, f, ensure_ascii=False, indent=2)

    In a production evaluation system, build_prompt should load a version-controlled template file. materialize should create an isolated directory for each task to prevent samples from contaminating one another.

    The result file should also include the model version, prompt version, and execution time. This metadata makes it easier to reproduce and compare evaluations later.

    6. Analyze Results and Control Bias

    Evaluation results can be affected by several types of bias. These should be controlled in advance.

    Prompt Bias

    Changing the wording of the same task can produce significantly different results. Use a fixed prompt template, and perform stability tests with multiple formulations for critical tasks.

    Randomness Bias

    The model may produce different outputs for the same input across multiple calls. Run each task at least three times when possible, and report a pass-rate range instead of relying on a single result.

    Data Leakage

    If tasks come from public repositories, the model’s training data may already contain the answers. Prefer unpublished internal tasks, and update the task set regularly.

    Review Bias

    Human reviews should be conducted blindly. Reviewers should not know which model or model version produced a sample.

    When analyzing results, the distribution of failure types is often more informative than the average score. For example, if a model’s intermediate-level failures are concentrated around missed edge cases, adding an edge-case checklist to the prompt may improve results more directly than switching models.

    7. Put the Evaluation into Practice

    Evaluation results should support concrete decisions, such as model selection, usage guidelines, and identifying workflows that require mandatory human review.

    A practical rollout can follow this sequence:

    1. Spend two weeks building a minimum task set covering three categories, with approximately 20 tasks per category.
    2. Run the complete evaluation workflow.
    3. Gradually expand the sample set.
    4. Whenever the model version or prompt version changes, rerun the same tasks.
    5. Compare changes across all scoring dimensions.

    Teams should also define clear usage boundaries. Model-generated code must go through the same review and testing process as human-written code. Review standards should remain consistent for both, regardless of how well the model performs in the evaluation.

    8. Summary

    The foundation of systematic evaluation is consistent input, consistent judgment, and repeatable execution. When tasks reflect real business requirements, scoring covers correctness, code quality, security, and maintainability, and sources of bias such as prompt variation, randomness, and data leakage are controlled, teams can replace subjective impressions with verifiable data and make more reliable technical decisions.