?
Solved

Unit Testing for .Net application (C#)?

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Simple Linear Regression
Six Sigma Control Plans
Suggested Courses

800 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