1

I have a class with following constructor: MyClass(QFile& file);. I want to unit-test it with Qt Test framework. How do I specify content of the file from a unit-test (without actually creating a real file)?

Vlad Shevchenko
  • 738
  • 1
  • 8
  • 19
  • 1
    You could use a `QTemporaryFile`. [More info](http://doc.qt.io/qt-5/qtemporaryfile.html). – Tarod May 15 '16 at 16:19
  • @Tarod Thank you, it worked for me. Although I still think that some kind of proxy would be better, so I don't have to create event temp file. – Vlad Shevchenko May 15 '16 at 17:01
  • Bundle the test data in a Qt resource and read it from there. Or implement your logic to operate on QIODevice. I don’t see what’s wrong with supplying the test data via resource-bundles files though. – Frank Osterfeld May 15 '16 at 23:16

0 Answers0