Testing LLM Code Generation: From Task Design to Result Evaluation

    This article presents a systematic methodology for evaluating large language models' ability to generate runnable code. It covers how to design test tasks across complexity levels, define measurable evaluation criteria, record and verify results through screen capture and automated checks, and analyze common failure patterns in long-form code generation. It also distills the practice into a reusable benchmarking workflow that any team can apply to their own business scenarios.

    Why Systematic Evaluation of Code Generation Matters

    As large language models rapidly evolve in code generation, the question developers care about most when selecting a model is: “Can this model actually write a runnable, complex interactive program?” A single quick Q&A or a one-off HTML snippet is not enough to judge a model’s true capability. A meaningful evaluation needs to be designed around three dimensions: task complexity, verifiability, and reproducibility.

    In one evaluation focused on 3D visualization and web interaction, I deliberately chose two high-difficulty tasks to observe how models handle long code, complex state management, and visual presentation.

    Designing the Test Tasks

    Task 1: A 3D Web Animation Scene

    The first task was to generate an interactive webpage depicting “a vast ring city after the tide recedes.” The evaluation dimensions included:

    • Scene modeling: building a bay panorama, plaza areas, waterways, and multiple viewpoints;
    • Stateful interaction: tide-level adjustment and view switching, with the scene updating in real time as the user interacts;
    • Offline usability: the generated single HTML file must open directly in a browser and run without external services;
    • Visual quality: whether the blue-toned atmosphere, lighting, and materials reach a “watchable” level.

    Tasks of this kind have a small entry point but great depth: the prompt is only one sentence, yet the model must decompose the scene structure, orchestrate animation logic, and handle user events. The final output often reaches thousands of lines of code.

    Task 2: A 3D Software Animation Script

    The second task was to generate an animation script runnable in professional 3D software, depicting “a mothership repair dock in orbit around Jupiter.” Compared with the web task, this additionally tests:

    • Familiarity with the 3D software’s API;
    • Choreography of the animation timeline and camera movement;
    • Correct use of object hierarchies, parent-child relationships, and transformation matrices.

    Evaluation Metrics and Process

    1. Core Metrics

    A serious evaluation should record at least the following:

    • First-pass success rate: whether the first run produces a runnable result;
    • Retry count: the number of retries after failure and cumulative time spent;
    • Final outcome: whether a usable artifact is produced within the allotted time/attempts;
    • Code quality: structural clarity, comments, and the proportion of hardcoding;
    • Runtime performance: frame rate, load time, and interaction latency.

    2. Timing and Screen Recording

    Record the screen and timestamps for the entire process. For example, in one test the first run ended at around 700 seconds, with several retries along the way, ultimately failing to produce a usable HTML file. This “failure case” is itself valuable evaluation data: it reveals problems such as syntax breakage, missing dependencies, or incomplete logic that can occur when a model works under long-context constraints.

    Screen recording also lets you reconstruct the interaction path: from panorama to close-up, from default state to adjusted state, verifying that every interactive element truly works rather than merely “appearing to run.”

    3. Control Groups

    Conclusions require controls. Driving different model sizes with the same prompt lets you observe how parameter scale and reasoning-chain length affect complex code generation. Common practice: keep the prompt exactly the same, keep the machine environment the same, keep the pass/fail criteria the same, and vary only the model under test.

    Patterns Observed Across Tests

    1. “Long Thinking” Helps, but with Diminishing Returns

    With enhanced reasoning enabled (i.e., the model performs a longer internal chain of thought before producing output), the first-pass success rate on complex tasks improves noticeably, especially for scenarios requiring multi-file structures or complex state machines. But the gains are not linear: beyond a certain point, longer reasoning dramatically increases latency while improvements in code quality flatten out. Developers should dynamically choose the reasoning effort based on task complexity.

    2. Failure Patterns Are Traceable

    Across multiple tests, typical failure modes for long-form code generation include:

    • Mid-output truncation: the model repeatedly re-emits a fragment partway through the code;
    • Missing references: using undefined variables or modules that were never imported;
    • Unbound events: UI elements render, but interaction logic is broken;
    • Over-decoration: extensive visual polish while core functionality remains weak.

    The most effective countermeasure is incremental delivery: generate the skeleton first, then fill in modules one by one, instead of asking for the complete project in a single output.

    A Reusable Evaluation Methodology

    Abstracting the above practices into a general process that any team can reuse:

    1. 1. Define the evaluation goal (webpage generation / script generation / refactoring...)
    2. 2. Design 2–3 tiered tasks: simple, medium, complex
    3. 3. Fix the prompt templates and lock in the pass/fail criteria
    4. 4. Run each task N times; record success rate, time, and retry count
    5. 5. Archive screen recordings as traceable evidence
    6. 6. Produce a comparison report, including analysis of failure cases

    It is also advisable to build automated result-checking scripts—for example, using a headless browser to load the generated HTML and detect console errors and whether key interaction events fire—combining subjective scoring with objective metrics.

    Conclusion

    Evaluating a large model’s code-generation ability is ultimately about measuring its ability to translate “fuzzy intent” into “runnable systems.” A single success or failure does not define a model. But a well-designed task matrix, rigorous recording, and reproducible pass/fail criteria make selection conclusions far more trustworthy. Rather than chasing benchmark leaderboards, developers are better served by building a small benchmark like this tailored to their own real business scenarios—far closer to actual value than any external evaluation.