Java Programming: Testing the Edges
Figure 1. The software development cycle.Copyright 2012 Cliffydcw, Wikimedia Commons {PD}
http://commons.wikimedia.org/wiki/File:SDLC_-_Software_Development_Life_Cycle.jpg
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.
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.
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.
- Troubleshooting is a problem-solving method used to identify the cause of a malfunction in a technological system.
Grades 6-8
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
Do you agree with this alignment? - STEL-7AA Illustrate principles, elements, and factors of design.
Grades 9-12
Do you agree with this alignment? - STEL-7DD Apply a broad range of making skills to their design process.
Grades 9-12
Do you agree with this alignment?
- judge the reasonableness of numerical computations and their results
Grades 9-12
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
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
Do you agree with this alignment?
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)
- Test Problem Scenarios (PDF), Three Implementations (PDF) and Test Case Results Worksheet (PDF), one each per student.
- Test Problem Scenarios (docx)
- Test Problem Scenarios (pdf)
- Test Implementation Scenarios (docx)
- Test Implementation Scenarios (pdf)
- Test Case Results Worksheet (docx)
- Test Case Results Worksheet (pdf)
- Test Case Challenge (docx)
- Test Case Challenge (pdf)
- Test Case Challenge Solutions (docx)
- Test Case Challenge Solutions (pdf)
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.
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.
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
- Make copies of the Test Problem Scenarios (PDF), Test Implementation Scenarios (PDF) and Test Case Results Worksheet (PDF), one each per student.
- Download/install a Java programming environment on the student computers.
With the Students
Part I
- Review the software design process with students and reiterate that the testing phase is a critical component of the process.
- Explain that writing test cases is a mini-software design process, inside of the larger design process.
- 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.
- Assign half the student pairs as "A" groups, and the other half as "B" groups.
- 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.
- 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.
- When the small groups have completed testing, bring the class together to discuss the results of their programming and testing.
- 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
- 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.
- 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.
- 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.
- 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.
- 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?
- 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.
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 (PDF) 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 (PDF).
- Java Code: Does It Work? Test and Test Again
- Java Programming: Testing the Edges
Contributors
Ryan Stejskal; Brian Sandall; Janet Yowell
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.
Copyright
2013 by Regents of the University of Colorado; original © 2012 Board of Regents, University of Nebraska
