Expose Private Methods For Testing? (Angular Question)

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ต.ค. 2024
  • In this video, I answer if it is ok to expose private methods for testing in Angular apps.

ความคิดเห็น • 5

  • @tntg5
    @tntg5 3 ปีที่แล้ว +1

    I just had an argument with a colleague. I agree that private functions shouldn't be accessed directly in the unit test, let alone exposing them publicly for the sake of testing them.
    If you feel you really need to test a private method, chances are that that method shouldn't be part of your class and should live in a static class where you can actually test it separately.

  • @anthonygriffiths122
    @anthonygriffiths122 2 ปีที่แล้ว

    I'm disappointed, you didn't give a good example. In fact your example class has no private methods.🤣

    • @ChristianLydemann
      @ChristianLydemann  2 ปีที่แล้ว

      As I said, I made the init method public, so I could test it as an example ;)

  • @tntg5
    @tntg5 3 ปีที่แล้ว +1

    I just had an argument with a colleague. I agree that private functions shouldn't be accessed directly in the unit test, let alone exposing them publicly for the sake of testing them.
    If you feel you really need to test a private method, chances are that that method shouldn't be part of your class and should live in a static class where you can actually test it separately.