Do not ever, ever, ever

..write code without a test!

Always start with a test! Even if it's a spike solution -- write a test!

UnitTests: Who's responsible for them?

Unit-tests are created by the developer(s). They are also maintained by the developer(s). Theres a misconception that the "QA Team" handles all the unit-tests, they don't. The QA team can utilize them while testing.

NUnit: Simplest way to setup unit tests in a project

The best way to setup unit tests for your application is to create a class-library in your project solution for NUnit tests only. The screen shot below shows this. Pay attention to the Project Names and their References.

UnitTests: How Use Cases help

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: UserSubmitsLetter
Actor: User, System
Pre-requisites: Unknown word has been generated
Post-Req: None, at the moment

Success path:
  1. User submits letter
  2. System deducts one point from user's allowed guesses
  3. User chooses to guess Word
  4. User submits correct guess for Word
  5. 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 another
4a. User's guess is incorrect
4a1. System deducts point from allowed guesses
4a2. System prompts user that word is incorrect
5a. 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 initials

From 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.