Unit test accessing private variables

前端 未结 6 1522
无人及你
无人及你 2021-01-05 04:55

I have a unit test class Tester; I want it to access private fields of a Working class.

class Working {
    // ...
    private:
            


        
6条回答
  •  灰色年华
    2021-01-05 05:51

    I agree with Trott's answer, but sometimes you're adding unit tests to legacy code that wasn't designed for it. In those cases, I reach for #define private public. It's just in unit tests, and it's just for when refactoring is too expensive to bother. It's ugly, technically illegal, and very effective.

提交回复
热议问题