Sunday, July 12, 2009

How to write test cases in c#.net for white box testing?

Iam new for white box testing.I have put in white box testing of c#.net applications.I am not understanding how the application is to be tested.which of them to be test.which should be not.How to write test cases for the functions.I want one good example of real life application Class.cs and the test cases of that Class.cs with clear explanation.Iam using the NUnit to test by dll's.

How to write test cases in c#.net for white box testing?
Hi, for whitebox testing it is clear that it is dealing code. You get ugly testing raw code :) It will get ugly :%26gt; But it is nice that your thinking of doing it since many people don't do it. Good software practicing, is good for the world!





Clearly the best Whitebox tool out there is CSUINT. It is similar to the other test suites for other programming languages.





Take a look at http://www.csunit.org/ There are many tutorials on that site as well.





Good Luck





PS: This tool works like the popular JUNIT!





For the good real life example :)





using System;


using csUnit;


using MyProject;


// MyProject is where the class to be tested exists.





namespace example {


/// %26lt;summary%26gt;


/// Summary description for FooTests.


/// %26lt;/summary%26gt;


[TestFixture]


public class FooTests() {


public FooTests() {


// nothing to do here


}


/// %26lt;summary%26gt;


/// Test the set and get methods of the MyClass.Value property


/// %26lt;/summary%26gt;


[Test]


public void TestValueProperty() {


MyClass obj = new MyClass();


Assert.Equals(0, obj.Value);


obj.Value = 25;


Assert.Equals(25, obj.Value);


}


}


}





using System;





namespace MyProject {


/// %26lt;summary%26gt;


/// This is the class to be tested..


/// %26lt;/summary%26gt;





public class MyClass() {


private int _ival = 0;


public void MyClass() {


_ival = 25;


}


public int Value


{


get


{


return(_ival);


}


set


{


_ival = value;


}


}


}


}





As you see I am creating an object and testing it if the value is correct:) As you see it is straight forward by using the Assertion Calls. I am testing if the object value is 0 and then 25 which are both true.





You do that for each function your testing like if we have getCarInfo, I make a stub to visuallize all the dependencies and then test that function like string car = getCarInfo(1); Assert.Equals("sedan", car); So if my function returns my expected result, then I am correct else there is a bug.





Good Luck on your testing! Takes a bit of time to do it :%26gt;


No comments:

Post a Comment