Hands-on Activity: Java Programming: Testing the Edges

Contributed by: IMPART RET Program, College of Information Science & Technology, University of Nebraska-Omaha

A circular diagram shows the typical software development steps: Requirement Analysis, Design, Implementation, Testing, and Evolution. A title in the center of the diagram: SDLC Software/System Development Life Cycle.
Figure 1. The software development cycle.
copyright
Copyright © 2012 Cliffydcw, Wikimedia Commons {PD} http://commons.wikimedia.org/wiki/File:SDLC_-_Software_Development_Life_Cycle.jpg

Summary

Students gain experience using the software/systems (engineering) design process, specifically focusing on the testing phase. This problem-based learning activity uses the design process to solve open-ended challenges. In addition to learning about test cases for testing software, students utilize the design process as a vehicle to work through a problem and arrive at a solution.

Engineering Connection

To produce a quality product, software engineers must fully test the written code. If this software development process step is not completed, it is likely that the user experience will not be good and thus, the product will not be used. To adequately test all aspects of code, all cases (possible situations) must be explored to see if the program acts as it was designed to function. A lack of software testing, or even ineffective testing, can lead to software updates (called patches) being necessary. This "hole" in the process can make software vulnerable to costly security breaches, both in human and economic terms. In the activity, students design test cases for a program to fully test the program.

Pre-Req Knowledge

This activity is designed for use in a Java programming class. The teacher should have a strong knowledge of Java programming and Java programming environments. Students must have a working knowledge of Java, although it does not have to be advanced. In order to design test cases as part of a larger design process, students must be able to develop code that needs to be tested.

Learning Objectives

After this activity, students should be able to:

  • Apply the software/systems design process to create test cases to properly test software to see if it functions correctly.
  • Relate the steps they complete in this activity to the full software/systems design process.

More Curriculum Like This

Using JUnit to Design Software Testing Programs

Students focus on the testing phase of the design process by considering how they have tested computer programs in the past and learning about a new method called JUnit to test programs in the future. JUnit is a testing method that is included with NetBeans (Java) installs or can be downloaded from ...

Java Code: Does It Work? Test and Test Again

Students focus on the testing phase of the software/systems design process. They start by exploring existing examples of program testing using the CodingBat website, which contains a series of problems and challenges that students solve using the Java programming language. Working in teams, students...

Testing Software Programs with JUnit

In this activity, students design tests for a provided Java class before the class methods are constructed using a process called test-driven development.

Do You See What I See?

Students explore the concept of optical character recognition (OCR) in a problem-solving environment. They research OCR and OCR techniques and then apply those methods to the design challenge by developing algorithms capable of correctly "reading" a number on a typical high school sports scoreboard....

High School Lesson

Educational Standards

Each TeachEngineering lesson or activity is correlated to one or more K-12 science, technology, engineering or math (STEM) educational standards.

All 100,000+ K-12 STEM standards covered in TeachEngineering are collected, maintained and packaged by the Achievement Standards Network (ASN), a project of D2L (www.achievementstandards.org).

In the ASN, standards are hierarchically structured: first by source; e.g., by state; within source by type; e.g., science or mathematics; within type by subtype, then by grade, etc.

  • Troubleshooting is a problem-solving method used to identify the cause of a malfunction in a technological system. (Grades 6 - 8) Details... View more aligned curriculum... Do you agree with this alignment?
  • The design process includes defining a problem, brainstorming, researching and generating ideas, identifying criteria and specifying constraints, exploring possibilities, selecting an approach, developing a design proposal, making a model or prototype, testing and evaluating the design using specifications, refining the design, creating or making it, and communicating processes and results. (Grades 9 - 12) Details... View more aligned curriculum... Do you agree with this alignment?
  • Refine a design by using prototypes and modeling to ensure quality, efficiency, and productivity of the final product. (Grades 9 - 12) Details... View more aligned curriculum... Do you agree with this alignment?
  • Evaluate the design solution using conceptual, physical, and mathematical models at various intervals of the design process in order to check for proper design and to note areas where improvements are needed. (Grades 9 - 12) Details... View more aligned curriculum... Do you agree with this alignment?
  • judge the reasonableness of numerical computations and their results (Grades 9 - 12) Details... View more aligned curriculum... Do you agree with this alignment?
  • know the characteristics of well-designed studies, including the role of randomization in surveys and experiments (Grades 9 - 12) Details... View more aligned curriculum... Do you agree with this alignment?
  • Identify questions and concepts that guide scientific investigations. Students should formulate a testable hypothesis and demonstrate the logical connections between the scientific concepts guiding a hypothesis and the design of an experiment. They should demonstrate appropriate procedures, a knowledge base, and conceptual understanding of scientific investigations. (Grades 9 - 12) Details... View more aligned curriculum... Do you agree with this alignment?
Suggest an alignment not listed above

Materials List

Each group needs:

  • computers with internet access and an appropriate Java development environment, such as NetBeans (www.netbeans.org) or Eclipse (http://www.eclipse.org/downloads/)

Note: install NetBeans or other open source Java programming downloads, such as http://introcs.cs.princeton.edu/java/mac/ (for Mac OS X) or http://textpad.com/ (for Windows)

Introduction/Motivation

This activity provides you with experience in the implementation of the software/systems engineering design process. This process is cyclical. You work through a series of steps to create a product that fits predefined criteria and functions correctly.

In the first part of the activity, you work in pairs to design and write a Java function that performs a certain task, as well as design and create test cases for another student group's Java function. Then you switch products to see if your test cases function correctly. After this is attempted, we will discuss the results as a class and brainstorm what could have changed or been implemented differently.

In the second part of the activity, you design a full test suite for a problem to determine if your solution properly tests the situation.

Vocabulary/Definitions

edge case: A test case whose input is near a "boundary" where the program changes from one behavior to another. For example, if a game allows a character to hold four items at a time, then edge cases include collecting the fourth item (the last item that the character can hold) and collecting the fifth item (an item that would exceed the character's carrying capacity).

error case: A test case whose expected result is an error. For example, for a program that divides two numbers, dividing by zero is an error case. A well-written program should have a plan in place to handle unexpected data in a reasonable manner; error cases test this plan.

test case: A specific set of inputs for a program or part of a program, along with the expected results of running the program with that input. Note that a test case must contain both the input and the output. A test can only help to verify a program's correctness if the expected output can be compared to the actual output of the test case.

Procedure

Background

Students gain experience with the software design process in two ways. First, the focus of the activity is properly testing code that has already been designed and written. This step is critical to the successful completion of a product. Secondly, student completes a mini-design process within the larger design process to develop the test cases required to properly test software. As students progress through this activity, they should note how the steps they are performing comprise the design process.

Before the Activity

With the Students

Part I

  1. Review the software design process with students and reiterate that the testing phase is a critical component of the process.
  2. Explain that writing test cases is a mini-software design process, inside of the larger design process.
  3. Have students each pick a partner to create Java functions and test cases. If an odd number of students, form one group of three students. Provide each student with the test problems handout, which presents two problems.
  4. Assign half the student pairs as "A" groups, and the other half as "B" groups.
  5. Each group writes a Java function for their one problem and a set of test cases for a different problem. For example, one group writes a Java function for Problem A and a set of test cases for the function based on Problem B. Conversely, another group writes a Java function for Problem B and a set of test cases for the function based on Problem A.
  6. After students have had sufficient time to create their functions and test cases, pair each "A" group with a "B" group to test both functions, using the test cases the two groups created.
  7. When the small groups have completed testing, bring the class together to discuss the results of their programming and testing.
  8. As a class, create a list of test cases for each function (A and B), and discuss how many and which test cases should be included in the set.

Part 2

  1. Next, provide students with the test implementation handout and the worksheet . Students should read a problem statement and discuss the requirements, as outlined in that statement.
  2. Once students understand the problem and its requirements, they create a set of test cases that determine whether a Java function correctly implements the requirements of the problem. Direct students to use the worksheet to organize information for this and the next two steps. Remind them that what they are doing is completing a design process to accomplish the task of testing software.
  3. Remind students to note whether each test case is a normal case, an edge case, or an error case. A complete test suite includes all of these types whenever appropriate.
  4. After students have created their test cases, have them use those cases to test Java functions I, II, and III in the test implementations handout.
  5. Discuss whether the functions correctly implement the requirements. Have students consider the following questions in their discussion:
  • If a function does not fulfill the requirements, what test case(s) show the problem?
  • How can the function be modified to fulfill the requirements?

Attachments

Assessment

Pre-Activity Assessment

What Do You Know? Discussion: Question students on their understanding of the software/systems (engineering) design process and how it can be applied to software development. Ask students the following (or similar) questions:

  • What are the steps of the software design process? (Answer: The steps include: analysis of the problem, design of a solution, implementation of the design, testing of the design, and possible extensions of the design.)
  • How can you apply the software/systems design process in the creations of test cases? (Answer: To create test cases, we must analyze what we are trying to test and design the tests; when the tests are used [implemented], we must test them to see if they do what we designed them to do; if modifications need to be made, we modify or possibly apply the tests to other programs; the creation of test cases is a complete design cycle.)

Activity Embedded Assessment

Observation/Teacher-Student Discussion: As students work, ask yourself the following questions as you observe them (Part 1) or ask the students (Part 2):

Part 1 assessment questions:

  • Did students write enough test cases to cover the range of possible input to the functions?
  • Did students account for edge cases and error cases, if appropriate? (In the attached problems, edge cases include, for example, weapons of weight 15 or 16 for red mages. Error cases include character classes, spells or weapons that are not on the list of valid inputs, as well as spell levels/weapon weights outside the specified range.)
  • Do student test cases include both input values and expected results?

Part 2 assessment questions:

  • If a function does not fulfill the requirements, what test case(s) show the problem?
  • How can the function be modified to fulfill the requirements?

Post-Activity Assessment

Test Case Challenge: Have students complete the Test Case Challenge handout, which asks them to apply what they have learned in the associated lesson and this activity to create a normal test case, an edge case and an error case for two described functions. See answers in the Test Case Challenge Solutions.

Contributors

Ryan Stejskal, Brian Sandall, Janet Yowell

Copyright

© 2013 by Regents of the University of Colorado; original © 2012 Board of Regents, University of Nebraska

Supporting Program

IMPART RET Program, College of Information Science & Technology, University of Nebraska-Omaha

Acknowledgements

The contents of this digital library curriculum were developed as a part of the RET in Engineering and Computer Science Site on Infusing Mobile Platform Applied Research into Teaching (IMPART) Program at the University of Nebraska-Omaha under National Science Foundation RET grant number CNS 1201136. However, these contents do not necessarily represent the policies of the National Science Foundation, and you should not assume endorsement by the federal government.

Last modified: February 9, 2018

Comments