Test List


Test List [1]

In Chapter 1, Test-Driven Development Practices, we stated that the first step is to brainstorm a list of tests for the task. The goal of this activity is to create a test list that verifies the detailed requirements and describes the completion criteria. One thing to keep in mind is that the list is not static. As you implement each test, you might have to revisit the list to add new tests or delete them as appropriate.

Let s try to write the test list for the unbounded Stack .

Unbounded Stack Test List

  • Create a Stack and verify that IsEmpty is true.

  • Push a single object on the Stack and verify that IsEmpty is false.

  • Push a single object, Pop the object, and verify that IsEmpty is true.

  • Push a single object, remembering what it is; Pop the object, and verify that the two objects are equal.

  • Push three objects, remembering what they are; Pop each one, and verify that they are removed in the correct order.

  • Pop a Stack that has no elements.

  • Push a single object and then call Top . Verify that IsEmpty is false.

  • Push a single object, remembering what it is; and then call Top . Verify that the object that is returned is the same as the one that was pushed .

  • Call Top on a Stack with no elements.

Choosing the First Test

There are differing opinions about which test to choose first. One says that you should choose the simplest test that gets you started and solves a small piece of the problem. Another says that you should choose a test that describes the essence of what you are trying to accomplish. For example, looking at the test list in the previous section, the simplest test is the first one: Create an empty Stack and verify that IsEmpty is true. This operation looks as if it would be easy to implement, but it does not provide a great deal of useful feedback when developing a Stack because the IsEmpty function is a supporting function.

A test in the list that is closer to the essence of the problem is the following: Push a single object, remembering what it is; Pop the object, and verify that it is equal to the object that was pushed. In this test, you are verifying that the Push and Pop methods work as expected. Which style to use really is a matter of personal preference because both will work.

There are times when the essence approach can take too much time to implement. If that is the case, you should choose a simpler test to get started. The suggestion that we give people who are learning TDD is to choose the simplest test approach and graduate to the essence approach after becoming familiar with the technique. Therefore, the first test that we chose to implement is Create an empty Stack and verify that IsEmpty is true.

[1] Beck, Kent. Test-Driven Development: By Example . Addison-Wesley, 2003.




Test-Driven Development in Microsoft .NET
Test-Driven Development in Microsoft .NET (Microsoft Professional)
ISBN: 0735619484
EAN: 2147483647
Year: 2004
Pages: 85

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net