I need to learn how to do unit tests for certain functions. I have googled and come accross some stuff, but all the examples are easy.
I read multiple articles on code project, but it didn't help. Usually, I see examples of unit testings functions that take in 1-2 parameters and perform addition/multiplication/etc.
I need to know how to unit test functions that return nothing, take in no parameters, and so on. For example, how do I write unit tests for a function that simply executes a SQL stored procedure? Or a function that just calls other functions?
For example:
Expand|Select|Wrap|Line Numbers
- private static void DoStuff()
- {
- int x = 0, y = 0, z = 0;
- Function1();
- x = Function2();
- if(x > y)
- Function3();
- }
Expand|Select|Wrap|Line Numbers
- private static void ExecProc(int vidID)
- {
- try
- {
- SqlCommand cmd = new SqlCommand("blah", conn);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.Add(new SqlParameter("@vidID", vidID));
- cmd.ExecuteNonQuery();
- }
- catch (Exception e)
- {
- Console.WriteLine("error: " + e.ToString());
- }
- }
I am using Visual Studio 2005 (C#) and have access to nUnit. Ideally, I'd like to learn how to write unit tests (manually) for the above examples, and then learn to use nUnit.
Any help you can provide is appreciated. Also, any links my googling didn't turn up would be appreciated as well. I'm really lost, and am sick of finding the same example that uses functions performing simple arithmetic.
Thanks!