Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Am I unit testing or integration testing?

General Tech QA/Testing
Max. 2000 characters
Replies

usr_profile.png
Lucky Negi

User

( 7 months ago )

I am starting out with automated testing and I would like to test one of my data access methods. I am trying to test what the code does if the database returns no records.

Is this something that should be done in a unit test or an integration test?

Thanks

usr_profile.png
Charles Kyobe

User

( 7 months ago )

 

If your test code connects to an actual database and relies on the presence of certain data (or lack of data) in order for the test to pass, it's an integration test.

I ususally prefer to test something like this by mocking out the component that the "data access method" used to get the actual data, whether that's a JDBC connection or web service proxy or whatever else. With a mock, you say "when this method is called, return this" or "make sure that this method is called N times", and then you tell the class under test to use the mock component rather than the real component. This then is a "unit test", because you are testing how the class under test behaves, in a closed system where you've declared exactly how the other components will behave. You've isolated the class under test completely and can be sure that your test results won't be volatile and dependent on the state of another component.

Not sure what language/technology you are working with, but in the Java world, you can use JMock, EasyMock, etc for this purpose.

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif