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
Syed ShakeerPosted Apr 27, 2014, 4:51 AM
Find the solution here http://www.c-sharpcorner.com/Blogs/15262/how-to-unit-test-a-method-that-return-void-type.aspx
Rajitha AththanayakePosted Apr 17, 2012, 5:41 PM
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);
}