Effectively Arranging Input Data for Test Cases

Learn and practice how to formulate input data for test cases.

Introduction

In the AAA pattern, we arrange data before we test a specific method. For example, we prepare some form of input data to test a method. There should be some thinking and intention in formulating this arranged data. The reason why arranging data requires deliberation is that most data, if purely randomized, will simply define general test cases. A general test case, or general case, is when code executes data that is arranged in a way that no value is on the edge or periphery of all its possible values.

Given that variables usually assume a wide variety of values, randomizing this data will lead to the general case data most of the time. Effectively arranging input data for test cases requires including as many edge cases as possible.

Identifying general case

Consider a method that transforms lowercase characters into uppercase characters. Already existing uppercase characters should remain unchanged. To determine the various general test cases, we need to think about dividing possible inputs into groups based on expected outcomes. This is known as equivalence partitioning. Equivalence partitioning is the act of dividing all inputs into groups based on expected outcomes. The result of equivalence partitioning is a set of equivalence classes. The four equivalent classes in the string converter example are shown below:

Equivalence class Input Output Number of test cases
Lowercase letter a - z A - Z 26
Uppercase letter A - Z A - Z 26
Non-alphabetic chars 0-9!@#,/"… 0-9!@#,/"… 42
Non-printable chars ^C,^S,TAB… ^C,^S,TAB… 34

The first group consists of input characters that are expected to be converted. The second group consists of input characters that are not expected to be converted. In the third group, we also expect no change in input. However, the input is not alphabetical. The same goes for the fourth group except the characters are not printable on screen.

As an exercise, you won’t implement such a method since this is already provided to you by the string class of .NET’s System namespace. Test whether the engineers over at Microsoft considered all four equivalence classes when releasing the ToUpper method. Note that you don’t need any application code to test this method since it is already included as part of the string class.

Get hands-on with 1200+ tech skills courses.