need to learn Unit Testing / nUnit (msvs2005)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • noway001
    New Member
    • Aug 2008
    • 1

    need to learn Unit Testing / nUnit (msvs2005)

    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:

    Code:
    private static void DoStuff()
    {
      int x = 0, y = 0, z = 0;
    
      Function1();
      x = Function2();
      if(x > y)
        Function3();
    }
    Or something like:
    Code:
    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 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!
Working...