Jump to content

.net Help In Unit Test


Recommended Posts

Posted

nenu oka kotha method create chesa. it is a void method

public void GetDataAndProcess()

{

//Calls a stored procudere, gets data

//passes the data from SP to a service

}

 

ee method is unit test rasina yemi test cheyyalemu kada?

unless if there is an exception in the database call or service call.

 

yevaru aina ilanti methods ki unit testing chesara??

Posted

basic ga methods should be unit testable.. nuvvu raasina aa 2 comments vere methods atihe vaatini test chey.. 

 

aa method ni test chesthey like database lo data undi, method execute chesi, result ki malli db query and doing Asserts on db data .. it will become functional test rather than unit test

Posted

I would Rather do the following 

 

Public void ProcessData()

{

  GetData();

 CallService();

}

public Data GetData()

{

call stored proc

}

 

I would Mock GetData() and  Unit test ProcessData.

 

If you really want to test the GetData then you can do integration test.

 

 

 

 

Posted

I would Rather do the following 

 

Public void ProcessData()

{

  GetData();

 CallService();

}

public Data GetData()

{

call stored proc

}

 

I would Mock GetData() and  Unit test ProcessData.

 

If you really want to test the GetData then you can do integration test.

Bhayya method ni break down cheyyadam varaku ardam ayyindi

but last 2 lines ardam kaaledu konchem detail ga cheppava 

Posted

K detail ga chepali ante.

 

mocking GetData

 

GetData ane function ni mock cheyachu i mean for example GetData ane method for suppose Data ane class lo undi anuko and IData is its interface then you can do following.

 

var testData = new Mock<IData>();

testData.setUp(x=>x.GetData).Returns("testDataObjectOrDataThatYouAreReturningFromStoredProc"); // This is how you mock GetData you might have to download moq dll which you can get online pretty easily 

 

 

Integration test is quite a big topic simple ga chepali ante  direct database ni hit chesi test chestav and do it only if you are selecting or inserting data and try to delete the dat after you insert but direct deletion query ayeta DO NOT USE Integration tests.

 

 

 

×
×
  • Create New...