Java tool for testing private methods?

前端 未结 5 2054
忘了有多久
忘了有多久 2021-02-20 10:32

There are different opinions on the meaningfulness of testing of private methods, e.g., here and here. I personally think it makes sense, the question is how to do it properly.

5条回答
  •  礼貌的吻别
    2021-02-20 11:01

    It seems like a lot of trouble to do this implementation. It may not be worth it. Rather just make the method package default.

    However, if you are determined to call private method, you can use setAccessible in yourDecapsulated_something class to allow call via reflection. So it's fairly simple.

提交回复
热议问题