By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,382 Members | 2,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,382 IT Pros & Developers. It's quick & easy.

need to learn Unit Testing / nUnit (msvs2005)

P: 1
Hi,
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
  1. private static void DoStuff()
  2. {
  3.   int x = 0, y = 0, z = 0;
  4.  
  5.   Function1();
  6.   x = Function2();
  7.   if(x > y)
  8.     Function3();
  9. }
  10.  
Or something like:
Expand|Select|Wrap|Line Numbers
  1. private static void ExecProc(int vidID)
  2. {
  3.   try
  4.   {
  5.     SqlCommand cmd  = new SqlCommand("blah", conn);
  6.     cmd.CommandType = CommandType.StoredProcedure;
  7.     cmd.Parameters.Add(new SqlParameter("@vidID", vidID));
  8.     cmd.ExecuteNonQuery();
  9.   }
  10.   catch (Exception e)
  11.   {
  12.     Console.WriteLine("error: " + e.ToString());
  13.   }
  14. }
  15.  
I know how to do unit tests for the simple examples, where functions take in a parameter or two, and give some output in certain cases. However, when there is no output, when there is no input, when they talk to the DB or execute stored procs...what are proper unit tests?

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!
Aug 16 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.