Skip to main content
4 of 4
typo fixed
Doc Brown
  • 220.6k
  • 35
  • 410
  • 625

Yes, it is a good idea to give your tests names of the example scenarios you are testing. And using your unit testing tool for more than just unit tests maybe ok, too, lots of people do this with success (me too).

But no, it is definitely not a good idea to write your tests in a fashion where the order of execution of the tests matters. For example, NUnit allows the user to select interactively which test he/she wants to be executed, so this will not work the way intended any more.

You can avoid this easily here by separating the main testing part of each test (including the "assert") from the parts which set your system in the correct initial state. Using your example above: write methods for creating an account, logging on and post a comment - without any assert. Then reuse those methods in different tests. You will also have to add some code to the [Setup] method of your test fixtures to make sure the system is in a properly defined initial state (for example, no accounts so far in the database, noone connected so far etc.).

EDIT: Of course, this seems to be against the "story" nature of your tests, but if you give your helper methods meaningful names, you find your stories within each test.

So, it should look like this:

[TestFixture] public class Authentication_Bill { [Setup] public void Init() { // bring the system in a predefined state, with noone logged in so far } [Test] public void Test_if_Bill_can_create_account() { CreateAccountForBill(); // assert that the account was created properly } [Test] public void Test_if_Bill_can_post_comment_after_login() { // here is the "story" now CreateAccountForBill(); LoginWithBillsAccount(); AddCommentForBill(); // assert that the right things happened } private void CreateAccountForBill() { // ... } // ... } 
Doc Brown
  • 220.6k
  • 35
  • 410
  • 625