Could you fool a StreamReader object?

I use a stream reader to import some data, and at the moment I'm hard-coded to set a small sample file in the test for the job.

Can I use Mock Objects with this and how?

+3
source share
4 answers

I do not see any points to make fun of StreamReader if you are not making a StreamReader class. If you need to provide test input through StreamReader, just read some predefined data from any suitable source.

+3
source

StreamReader is a concrete class, therefore many mocking systems will not allow you to mock it. TypeMock Isolator , however.

, , , . , StreamReader , MemoryStream - .

+2

When testing code that depends on streams, streams, and streaming, I usually use the memystream object for testing. There is no mocking structure.

+1
source

You can use the factory method to return a TextReader, which can be either a mockup or an actual StreamReader.

+1
source

Source: https://habr.com/ru/post/1696859/


All Articles