liveBook · Manning

Logical code sections

As explained in Software Testing with Generative AI

Logical code sections are semantically coherent portions of source code partitioned according to program structure rather than arbitrary line boundaries.

Logical code sections partition source by semantic structure instead of arbitrary line boundaries. A section may describe a class declaration, field declarations, or a complete method with its containing code, preserving useful context for dataset entries. section 12.2.1

Use the technique to balance detail against context:

  • Avoid line-by-line slicing when isolated lines provide insufficient context for instructions and expected outputs. section 12.2.1
  • Extract sections by parsing the Java class structure, then query the resulting semantic tree. section 12.2.1
  • Accept greater parsing complexity when contextual sections produce more useful fine-tuning data. section 12.2.1

Class and method entries

A dataset can pair an instruction asking for a class declaration with the declaration itself, or ask how a setup method works and return the complete method. Each entry represents a meaningful code unit rather than one line. section 12.2.1

{"instruction": "What is the class declaration for
➥BrandingServiceIT","output": "@ExtendWith
➥@SpringBootTest
➥@ActiveProfiles
public class BrandingServiceIT { }"}
{"instruction": "How does the method setup Restito work for
➥BrandingServiceIT?","output": "
➥@BeforeEach
➥public void setupRestito(){
➥whenHttp(server).match(post("/auth/validate"))
➥.then(status(HttpStatus.OK_200));
➥}"}

Browse representative instruction-and-output pairs for class declarations and complete setup methods. section 12.2.1

How Software Testing with Generative AI covers it

How deep it goes
Explains the partitioning rationale and extraction workflow, but stops short of detailing the parser implementation.
Examples
Uses class declarations, field declarations, complete methods, and setup-method instruction pairs as concrete dataset entries.
What it assumes
Assumes familiarity with source-code datasets and instruction-based fine-tuning, while illustrating the structural partitioning rationale.
What you can do after
Build it from scratch by parsing Java files, constructing a semantic tree, and extracting structurally meaningful dataset entries.
How it connects
Connects semantic code sections with instruction-based fine-tuning, datasets, Java classes, semantic trees, and JavaParser.

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.