Generate Boundary Condition Unit Tests for GitHub Copilot

Get a comprehensive unit test suite focusing on edge cases, null pointers, and arithmetic overflows for any function you paste.

Agent prompt for ChatGPT and Claude

Prompt

Prompt
Act as a Senior Software Engineer. I will paste a code function below. Your task is to generate a comprehensive suite of unit tests focusing exclusively on boundary conditions. Follow these rules: 1. Create a table of test cases that includes the input scenario, the expected behavior, and the specific boundary condition being tested. 2. Write the actual test code using a standard testing framework like PyTest, JUnit, or Jest. 3. Ensure no external mocks are used; if a dependency is required, suggest the minimal structural change instead. 4. Include tests for empty collections, null inputs, maximum integer values, and off-by-one errors. Output format: 1. Test Case Table 2. Unit Test Code Block. Please wait for me to paste the code after you acknowledge this request.

Example output

Test scenarios and expected behaviorBoundary cases covered for the average method
ItemExpected behaviorBoundary condition
Null input listThrow IllegalArgumentExceptionNull pointer safety
Empty listReturn 0.0Empty collection handling
List with one valueReturn value as floatOff-by-one boundary
Integer.MAX_VALUE listHandle overflow logicArithmetic overflow

Example for: a Java method calculating the average of a list of integers.

Test Case Table
ScenarioExpected BehaviorBoundary Condition
Null input listThrow IllegalArgumentExceptionNull pointer safety
Empty listReturn 0.0Empty collection handling
List with one valueReturn value as floatOff-by-one boundary
Integer.MAX_VALUE listHandle overflow logicArithmetic overflow
Unit Test Code
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;

class StatisticsUtilityTest {
    @Test
    void testAverageWithNullInput() {
        assertThrows(IllegalArgumentException.class, () -> StatisticsUtility.calculateAverage(null));
    }

    @Test
    void testAverageWithEmptyList() {
        assertEquals(0.0, StatisticsUtility.calculateAverage(Collections.emptyList()));
    }

    @Test
    void testAverageWithSingleElement() {
        assertEquals(5.0, StatisticsUtility.calculateAverage(Arrays.asList(5)));
    }

    @Test
    void testAverageWithMaxIntegerValues() {
        // Testing potential overflow when summing two MAX_VALUE integers
        assertEquals(Integer.MAX_VALUE, StatisticsUtility.calculateAverage(Arrays.asList(Integer.MAX_VALUE, Integer.MAX_VALUE)));
    }
}

This assumes the standard Java library is available and no external frameworks are required.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces the model to identify edge cases before writing code.
  • Uses a table format to ensure all boundary types are covered.
  • Bans mocks to keep tests fast and focused on pure logic.

Copy this prompt into GitHub Copilot Chat, ChatGPT, or Claude. After the model acknowledges, paste your function code. This is ideal for identifying logic gaps in critical utility functions before committing code to your repository.

Common edits

  • Specify the testing framework if the model defaults to the wrong one.
  • Add a rule to include performance tests if the function processes large data.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

Agent OrchestrationClaude

Design Mock Tool Fixtures for Agent Trajectory Testing

Generate deterministic mock tool responses to test agent decision trees, edge-case failures, and schema-breaking payloads without live API usage or costs.

AI Coding AgentsClaude Code

Generate Reproducible Bug Fix Specs for Coding Agents

Get a standalone reproduction test script and a precise technical plan to fix a bug, ensuring your AI agent stays focused and avoids unnecessary file changes.

Sync Test Factories and Fixtures with Database Migrations

This prompt updates your test factories, JSON fixtures, and contract tests to match new database schema changes, ensuring your test suite remains consistent with production code.

Debug Regex and Parsers with GitHub Copilot

Generate an automated audit of regular expressions or parser snippets that flags catastrophic backtracking, isolates edge cases, and produces unit test fixtures.

AI Coding AgentsClaude Code

Evaluate Coding Agent Test Suites for False Positive Traps

Audits agent-generated unit tests to catch tautological assertions, over-mocking, and tests that still pass when core business logic is disabled.

Turn Sentry Errors into Reproducible Codex Test Cases

Transforms a production Sentry stack trace and context payload into a self-contained failing unit test designed for Codex repo tasks.