I'm exploring Test Driven Development and Unit testing in VS2008 and was wondering if anyone had any real world examples on how i would write unit tests on objects that modify a sql database.
For non sql routines, tests are easy to write. If i wanted to test an add routine in a calculate object the test would just be as follows.
Now comes the tricky part. Lets say I have an object that will increment a sql record's integer attribute when called. How would I write a test for this?
For non sql routines, tests are easy to write. If i wanted to test an add routine in a calculate object the test would just be as follows.
Code:
1: [TestMethod]
2: public void AddNumbersTest()
3: {
4: int result = Calculate.Add(2, 2);
5: Assert.AreEqual(result, 2 + 2);
6: }]
Now comes the tricky part. Lets say I have an object that will increment a sql record's integer attribute when called. How would I write a test for this?
Code:
public void Increment(int recordID) {
using(SqlCommand cmdIncrement = new SqlCommand("update myTable set myAttribute = myAttribute+1 where recordID = @recordID"))
{
....
}
}