Hi,
I am working on a component based application. I have a method that does some calculation and returns nothing.
say:
public void DoSomething(int x, int y)
{
// do something
}
How to write testing for it.
I can pass some dummy x,y values. But how and what we can Assert in the unit test project.
Any help would be appreciated.
Thanks.
Regards

Rajitha Aththanayake2 reputationPosted Apr 17, 2012, 1:41 PM EDT
public class MyClass
{
public int Result { get; set; }
public void DoSomething(int x, int y)
{
Result = x + y;
}
}
[TestClass]
public class FileDataViewModelUnitTests
{
[TestMethod]
public void MyTestMethod()
{
//Arrange
var myClass = new MyClass();
//Act
myClass.DoSomething(3, 5);
//Assert
Assert.Equals(myClass.Result, 8);
}
Syed ShakeerRank #777 · 3K reputationPosted Apr 27, 2014, 12:51 AM EDT
Find the solution here http://www.c-sharpcorner.com/Blogs/15262/how-to-unit-test-a-method-that-return-void-type.aspx