954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to write Moq unit testing for void methods

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

surajrai
Newbie Poster
16 posts since May 2010
Reputation Points: 10
Solved Threads: 1
 

Does the method change anything external to the method?
If so, you can see if that changed or that it does not throw an exception...

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

In addition to what thines said above, if the DoSomething method acts on an object you could mock out the object and see if a particular method was called with a given set of parameters

cale.macdonald
Junior Poster
153 posts since Jun 2009
Reputation Points: 16
Solved Threads: 31
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: