473,725 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to learn Unit Testing / nUnit (msvs2005)

1 New Member
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
0 1240

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

Similar topics

1
2551
by: serge | last post by:
I've started researching on Unit Testing and I must admit I had never heard of Unit Testing until a couple of months ago. Obviously I am interested in Unit Testing Stored Procedures. I read the TSQLUnit documentation (not all of it) and i also ran into a newsgroup post saying TSQLUnit is very small compared to NUnit. The conclusion I am making out of this post is that I should rather spend time resarching/reading about NUnit than...
5
2869
by: Pete | last post by:
Hi folks, I've been looking at unit testing frameworks (csUnit, NUnit, etc) and have gathered some info on them (see the older thread on c# 2004). My question is this: how do they work with windows forms? All the samples I've seen are for trivial testing, such as making sure a property sets it's value correctly. How would I go about testing, for example, a custom control? All my testing seems to be visual (i.e. compile, run, see if it...
14
2749
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
2
9743
by: Curtis Justus | last post by:
Hi, I've been searching for solutions to two issues that are undoubtedly common to everybody. The first is how do my team and I adequately perform unit testing. The second is how can I measure a load on my application? In the past, we would write our class and then come up with some logic in a console or win app to test it. I have since found NUnit which seems to be pretty cool. BTW: if anybody has some XSLTs that provide...
6
4405
by: Droopy | last post by:
Hi, I want to add unit tests in my application using NUnit. At first, I thought to add unit tests in the class that is tested, enclosed in a conditional attribute to remove these unit tests from release code. Though, there is (at least) 2 problems working like that : 1) the class can becoming very large if there is a lot of tests 2) when releasing, the NUnit dll should not be needed => it should not be referenced.
7
1882
by: Diffident | last post by:
Hello All, Can anyone please suggest me a good unit testing tool. I have seen NUnit but not sure on how I can use it to test my methods which involve session variables, viewstate variables, textbox values. I understand that NUnit is more suitable for OO methods which take set of parameters and return an output parameter. How about tools for testing methods which use state variables and form values?
4
18967
by: Dat AU DUONG | last post by:
Hi, I am new to Unit testing, could you tell me where I could find information (hopefully step by step) and what is the benefit of unit testing. I am a sole developer in a company, therefore I don't get expose to much of this technology. Thanks in advance. Regards Dat.
6
1473
by: Jeremy | last post by:
I understand what a unit test is. No problem there. What I'm wondering is what, specifically, do most of you more experienced developers mean by "writing" a unit test. Am I correct to believe that you are referring to some way you *document* your tests? If yes, can you provide some example? Given the huge amount of unit tests that go on with any non trivial application dev project I'd like to think that there is some standard template...
8
1437
by: Eric | last post by:
I've spent some time this morning looking into unit testing frameworks for ASP.NET 2.0, but none seem satisfactory. I don't have Visual Studio Team Edition, so apparently I can't use Microsoft's solution, and TestDriven.net has no support for web applications. The best I have found is to use NUnit on the .dll that is created when the site is published. However, I have found that this .dll is not updated with each publish, instead new...
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.