Solved

Unit Testing for .Net application (C#)?

Posted on 2012-03-21
1
414 Views
Last Modified: 2013-12-13
Hi,

Can you direct me to a good Unit Testing for c# tutorial site?

I am using the Visual Studio 2008/2010 for development.
What else do I need to do the Unit Testing?

I read a few simple tutorials but I still have many questions.
For an instance, this article uses pretty simple Person class as en example
http://www.dreamincode.net/forums/topic/108976-c%23-unit-testing-basics/

You have a get name, get age functions.

What if your methods are not simple, what they don't return anything.
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 37750823
The basis of unit testing is to see if a system returns the proper data.

Put at its simplest, you test a method by sending it different sets of data and then see if the result fits within the expected return value(s).

Methods that do not return anything usually do something.

The method might create a file. Then you aim is to test if the file is in the proper format. Then it is up to you to validate the resulting file and create an Assert according to the problems you might encounter. It might be as simple as comparing the resulting file with one containing what you are expecting, but it can be very involved if you want to test with different sets of data.

The method should write ot a database? Then you test method should read the database to see if the write did work. Something akind to the following:
bool expected = true;
bool result;

result = // Code that test for the presence of the expected data
Assert.AreEqual(expected, result, "Expected data not found in the database")

Open in new window

You did test against the expected result, even if it was not "returned" by your method.

If your method does not return anything or generate information somewhere, then what do you want to test? The flow of execution? How it reacts to users interaction? Then you are not doing unit testing and should use other techniques.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Six Sigma Control Plans
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question