I have been doing some research on test driven development and find it pretty cool.
One of the things I came across was that when you write your tests, there is an order of execution of your setup and test methods ([Setup] and [Test]).
Are there others that you can use while testing and if so what is the execution order of those, such as a dispose or something? I saw test fixture setup, but not too familiar with that one.
Example:
When I run the test, it does the [Setup] first and then runs the [Test] when it goes to the next test it runs the [Setup] again and then goes to the [Test].
I am using NUnit if that helps.
Here is a truncated example of what I have setup:
using NUnit.Framework;
namespace TestingProject
{
[TestFixture]
public class CustomerService_Tests
{
public string MyAccount = string.Empty;
[SetUp]
public void Setup()
{
MyAccount = "This Account";
}
[Test]
public void Validate_That_Account_Is_Not_Empty()
{
Assert.That(!string.IsNullOrEmpty(MyAccount));
}
[Test]
public void Validate_That_Account_Is_Empty()
{
Assert.That(string.IsNullOrEmpty(MyAccount));
}
}
}
So, when I run the tests, it does the setup, and then the first test, then setup and then the 2nd test.
My question is what other types can I use while testing such as [Setup] and [Test] and what is the order of execution for these.
Using NUnit (not sure about others) you have the following order of executions:
TestFixtureSetup
Setup
Test
TearDown
Setup
Test
TearDown
TestFixtureTearDown
Every time you run your tests it will always execute in that order.
If you take a look at the following code, you can see an exact replica of what I am talking about. You can even copy and paste this code and it should work (using NUnit, not sure if it will work with others).
If you run this in debug mode, and put a break point on each of the methods, you can see the order of execution while you debug.