<p>I use a stream reader to import some data and at the moment I hardcode a small sample file in the test to do the job.</p>

<p>Is it sensible to use Mock Objects with this and how ?</p>

[{'answer_id': 62175, 'author': 'Mendelt', 'author_id': 3320, 'author_profile': 'https://Stackoverflow.com/users/3320', 'pm_score': 1, 'selected': False, 'text': '<p>When testing code that depends on streams, streamreaders and streamwriters I usually use the memorystream object for testing. No mocking framework needed here.</p>\n'}, {'answer_id': 62176, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 3, 'selected': True, 'text': "<p>I don't see any points to mock StreamReader unless you're making StreamReader derived class. If you need to provide test input via StreamReader, just read some predefined data from any suitable source.</p>\n"}, {'answer_id': 62181, 'author': 'Blair Conrad', 'author_id': 1199, 'author_profile': 'https://Stackoverflow.com/users/1199', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx#Mtps_DropDownFilterText" rel="nofollow noreferrer">StreamReader</a> is a concrete class, so many mocking systems won\'t allow you to mock it. \n<a href="http://www.typemock.com/" rel="nofollow noreferrer">TypeMock Isolator</a> will, however.</p>\n\n<p>You may find you want to mock it if you need to force errors to come from the reader, rather than just having it supply data to your class under test. If you don\'t need this functionality, you may be just as far ahead <a href="http://msdn.microsoft.com/en-us/library/yhfzs7at.aspx" rel="nofollow noreferrer">constructing</a> a StreamReader from some other Stream, such as a <a href="http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx" rel="nofollow noreferrer">MemoryStream</a> - this way you don\'t need to go to disk for your data.</p>\n'}, {'answer_id': 62185, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 1, 'selected': False, 'text': '<p>You can use a factory method to return a TextReader that could either be the mock object or an actual StreamReader.</p>\n'}]
['https://Stackoverflow.com/questions/62159', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4694/']