Here's an example of a simple format for
use cases -- which have made it a little easier for me when doing requirements gathering -- to see what needs to be tested defined by the following task from developing Hangman.
Task:
User submits a letter to guess at an unknown word
UseCase:UC: UserSubmitsLetterActor: User, SystemPre-requisites: Unknown word has been generatedPost-Req: None, at the momentSuccess path:- User submits letter
- System deducts one point from user's allowed guesses
- User chooses to guess Word
- User submits correct guess for Word
- System prompts user to play again
Exceptions:1a. Letter has already been submitted for guess 1a1. System does not deduct a point for an already guessed letter 1a2. User is prompted that letter has already been guessed, choose another4a. User's guess is incorrect 4a1. System deducts point from allowed guesses 4a2. System prompts user that word is incorrect5a. User has beaten a previous record for lowest amount of guesses for current word 5a1. System prompts user to enter Initials 5a2. User enters initials 5a3. System persists user's initialsFrom the above example, although very simple, shows how a UseCase can map to a Unit test. Let the dissection proceed!
The successful path of execution starts when the
User submits letter(1). If a correct letter is guessed then the
System deducts one point from user's allowed guesses (2). If the
Letter has already been submitted for guess (1a) we can test to make sure that a point has NOT been deducted from the amount of guesses left for the word. If the
User submits correct guess for Word (4) a unit test can test the prompt returned. If the
User's guess is incorrect (4a) then a test can check to see if a point has been deducted from the remaining guesses and that a specific message will be returned.
The above are also limited, these were just the basic tests to test 1 value for each step in the UseCase. We'll definitely use this task as a base for the first couple of NUnit code examples.
Don't let your code or tests suck due to weak requirements and lame analysis. UseCases provide a good base to the baseless.
Labels: TDD Exercises, Use Cases