Unit Testing a Method

Posted by Bantudotnet under ASP.NET on 8/17/2012 | Points: 10 | Views : 998 | Status : [Member] | Replies : 6
How to unit test a method having interface as argument?

I need to just test the variable should not accept null values i.e. argument exception. I am new to unit testing so could not get.

My Sample Code:

public BooksInfo GetBookInfo(IBookMarket bookinfo)
{ }

Here i need to pass null to "bookinfo " and test exception is raising or not.




Responses

Posted by: Gopesh9 on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
What is IBookMarket and BooksInfo in
public BooksInfo GetBookInfo(IBookMarket bookinfo)



G. S.
.Net Developer

Bantudotnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bantudotnet on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
@Gopesh,

IBookMarket
is an interface having few methods declared in it.

booksinfo
is of type
IBookMarket


this is only sample code.

Bantudotnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gopesh9 on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
You can use like this, I hope this will help you. Maybe you can change this according to your requirement.

BooksInfo? book = null;

if(bookinfo == book)
{
return book;
}


G. S.
.Net Developer

Bantudotnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bantudotnet on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you.

Here i want to unit test and i am new to this too. Query string format, Is this good practice in unit testing?

Bantudotnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gopesh9 on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
I dnt know much about testing, but i know that Query String is not a good practice. By the way I am sorry i cant help you with Testing.

G. S.
.Net Developer

Bantudotnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bantudotnet on: 8/17/2012 [Member] Starter | Points: 25

Up
0
Down
No prob.

Thanks for your response.

Bantudotnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response