?
Solved

Unit Testing for .Net application (C#)?

Posted on 2012-03-21
1
Medium Priority
?
420 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Starting up a Project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

864 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