Skip to content
Computer Science · 9th Grade

Active learning ideas

Testing Functions with Inputs

For 9th graders, testing functions with inputs moves beyond fixing errors to building confidence in code before it runs. Active learning works here because students must design inputs, predict outputs, and confront their own assumptions about how code should behave.

Common Core State StandardsCSTA: 3A-AP-17
20–40 minPairs → Whole Class4 activities

Activity 01

Problem-Based Learning40 min · Pairs

Test Case Design Workshop

Each student writes a function and then designs a test suite with at least six cases: two typical inputs, two boundary values, and two invalid inputs. They trade functions with a partner, who runs the test suite and reports which cases passed and which failed, with notes on what the failure revealed.

Explain the importance of testing functions with different inputs.

Facilitation TipDuring Test Case Design Workshop, have students work in pairs to write test cases for a function you provide first, then for each other's functions to model the peer review process.

What to look forStudents exchange functions they have written. Each student then writes 3-5 test cases for their partner's function, specifying the input and the expected output for each. Partners then run the tests and discuss any discrepancies.

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 02

Think-Pair-Share20 min · Pairs

Think-Pair-Share: What Could Go Wrong?

Present three function descriptions without code. Students individually list at least four inputs that could cause problems, then compare lists with a partner and categorize inputs by type (valid typical, valid edge, invalid). The class discusses which categories are most often overlooked.

Design a set of test cases for a given function.

Facilitation TipIn Think-Pair-Share: What Could Go Wrong?, assign roles so one student explains potential issues while the other records test cases, then switch roles to deepen perspective-taking.

What to look forProvide students with a simple function (e.g., a function to calculate the area of a rectangle) and a list of potential inputs. Ask students to identify which inputs are typical, which are edge cases, and which are invalid, and to explain their reasoning for each.

UnderstandApplyAnalyzeSelf-AwarenessRelationship Skills
Generate Complete Lesson

Activity 03

Problem-Based Learning30 min · Pairs

Bug Hunt: Failing Tests

Provide pairs with a function and a set of test cases, some of which fail. They must identify the input pattern that causes failure and trace through the code to find the bug, without modifying the tests. They document their findings as a structured bug report.

Identify common errors that can be found by thoroughly testing function inputs and outputs.

Facilitation TipFor Bug Hunt: Failing Tests, provide intentionally buggy code and broken test cases so students must debug both the function and the test logic to see how tests guide corrections.

What to look forGive students a function that contains a subtle bug. Ask them to write one test case that will reveal the bug and briefly explain why that specific input causes the function to fail.

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 04

Gallery Walk30 min · Small Groups

Gallery Walk: Test Coverage Analysis

Post four functions with their test suites. Students annotate which inputs are missing from each test suite, writing specific test cases that should be added. The class votes on the most critical missing test for each function and discusses why that case matters.

Explain the importance of testing functions with different inputs.

What to look forStudents exchange functions they have written. Each student then writes 3-5 test cases for their partner's function, specifying the input and the expected output for each. Partners then run the tests and discuss any discrepancies.

UnderstandApplyAnalyzeCreateRelationship SkillsSocial Awareness
Generate Complete Lesson

A few notes on teaching this unit

Start with small, relatable functions so students focus on testing strategy rather than complexity. Use public debugging sessions where you model thinking aloud about which inputs to test and why. Avoid rushing to fix bugs; instead, emphasize that tests should expose errors before code reaches users. Research shows that students who practice testing early develop stronger debugging habits that transfer to larger projects.

Students will create test cases for functions, identify edge cases, and recognize that a single passing test does not guarantee correctness. Successful learning is visible when students explain why certain inputs reveal bugs and adjust their testing strategies accordingly.


Watch Out for These Misconceptions

  • During Test Case Design Workshop, some students may think that testing a few obvious inputs is enough.

    Use the workshop to push students to include edge cases and invalid inputs, then have them swap test suites with peers to challenge each other's assumptions about sufficient coverage.

  • During Think-Pair-Share: What Could Go Wrong?, students may assume their partner's function is flawless.

    Ask students to intentionally brainstorm ways their partner's function could fail, then write test cases for those scenarios to reveal gaps in their own expectations.

  • During Bug Hunt: Failing Tests, students may believe the test case is correct and the function is broken when the opposite is true.

    Have students justify each test case's expected output before running it, then compare their reasoning to the function's actual behavior to identify whether the bug lies in the test or the code.


Methods used in this brief