Abstract
Microsoft Visual Studio and .NET have their own UnitTest framework that is separate from NUnit and other Automation Testing Frameworks.
First of all, let's understand what a Framework is. Framework is an Architectural term and it means "Collection of Components".
Defining SUT (system under test)
Let's say I have developed some business logic for my application which performs some mathematical calculation based on user input and is available via a MathLibrary.dll. Hence, it is very critical to have the business logic well tested on various parameters that the user might pass. So my business logic is "System Under Test " from a Unit Test perspective. The source code of this MathLibrary business logic component is as shown below.
using System;
namespace MathLibrary
{
public class MathClass
{
public int Sum(int n1, int n2)
{
if(n1<=0 && n2<=0)
{
throw new ArgumentException("No Zero or Negative are allowed");
}
else
{
return n1 + n2;
}
}
}
}
Since it's a DLL component, test coverage of this is very critical for ensuring that the business logic is intact and returns the correct results.
To do so, instead of relying on a Manual Test Process through a UI that will be very cumbersome and tedious to continuously test the sanity of the business logic, we can choose to Automate this test process.
As you might have noticed, we have written the Sum function (in MathLibrary.dll) in a Test Driven, style. In other words, the parameters passed are also being validated for all the possible test scenarios.
- If the argument is positive and non-zero then the sum of the arguments passed is returned.
- If the argument passed is 0 ("zero") then an exception is thrown
- If the argument passed is negative then an exception is thrown
How to approach Test Automation in general?
Irrespective of what Unit Test tool and development techniques you use, the test process depends on the following two things.
- Expected: Before we perform a test our Test case tells us what to expect by this test case to verify success; for example in the case of a Sum taking two ints, we expect it to return the exact results of adding two numbers.
- Actual: When you perform the test what your result is.
If Expected meets the Actual then your Test Case has Passed, otherwise, your Test Case has Failed.
Hence we have to do Test Coverage for all the Test Cases in the test scenarios described previously.
To do so, we will use Microsoft Visual Studio 2008 or 2010 and then open a New Test Project as shown in the following image.




kalu singh raoPosted Jul 1, 2016, 2:08 AM
Nice...
Vignesh ManiPosted Jun 9, 2016, 4:51 AM
Good one Sir
Santhakumar MunuswamyPosted Jun 8, 2016, 11:28 PM
Thank you for well written
Sonu ChaudharyPosted Jun 8, 2016, 2:50 PM
good one ..
Asad AliPosted Jun 8, 2016, 10:57 AM
Good one
Debasis SahaPosted Jun 8, 2016, 7:09 AM
Nice article..
RajaPosted Jun 8, 2016, 5:19 AM
Good One..
foued kheddarPosted Feb 2, 2013, 8:51 AM
thank you ...