Creating mockobject of Qfile by replacing Qbuffer possible?
-
Hi ya'll,
For the unit testing purpose, I have a QFile writing to and reads from a file. However, I need to replace this file as a memory, such as QBuffer, since they are from the same base class QIODevice, so it won't be necessary to create the file to perform a unit test.
How can I write a method with QFile so it would write to Qbuffer or QByteArray, so I could verify it's contents acting like in memory instead? Likewise, for the other way around reading a Qbuffer from QFile.
What's the best way to approach this? It may require some advanced OOP with inheritance, but I'm not sure it will work.
Thanks in advance.
-
Hi,
One way is to use QIODevice rather than QFile for your method.
That way you can pass whatever you want for your tests.
-
Don't use QFile but your own class which either routes to a QFile or QBuffer/QByteArray.
-
Hi,
One way is to use QIODevice rather than QFile for your method.
That way you can pass whatever you want for your tests.