Solved

Unit Testing for .Net application (C#)?

Posted on 2012-03-21
1
406 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
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now