dimanche 4 février 2018

How to test private member functions of a class using QTestLib?

I am using QTestLib for Unit Testing and i ask myself how to test private member functions of my classes. I would like to build a test suite for an in-house shared library.

What strategies do i have in Qt's context for this ?

I thought that testing private member functions through public members functions could be a good starting point :

class A {

   public:
      // add an extra function that is only relevant for testing
      int value() const {
         return theFunctionIWantToTest();
      }

   private:
      int theFunctionIWantToTest() {
         // implementation ..
      }      
}

But the problem is that i don't need this getter in the class A after testing.

I am not very experienced with QTestLib and so far i could not find anything in Qt's Doc related to this specific point.

Thanks.

Aucun commentaire:

Enregistrer un commentaire