Is Structural Inspection Part of Your Unit Testing Strategy?

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ต.ค. 2024

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

  • @codingbloke
    @codingbloke ปีที่แล้ว +8

    Another excellent video. The concept of Structural Inspection is new to me so thank you.

  • @vulcanobyte
    @vulcanobyte ปีที่แล้ว +2

    Thank you very much Mr. Horvat very good video💯

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว

      I'm glad to hear you liked it!

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

    Am not I testing the response structure when I do behavioral tests? Isn't this technique only marginal beneficial?

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว +3

      If you are testing the result structure in behavior tests, then I would argue that there is something wrong with the definition of behavior.
      Behavior tests should assert attributes of the result, so to decouple from implementation. That leaves it open to the implementer to choose from multiple possible implementations, some of which affect the structure of the result - some structures being more preferable than the others.
      That is where the structural inspection comes to the table, verifying that the result has structure that is preferred, even though any structure would exhibit the same behavior.
      In the example from the video, recursive composite discounts would behave the same as their flattened counterpart, but only the latter is allowed. The problem with recursive composite objects is that they have a nasty corner case where the tree of objects degenerates into a list. With recursive lazy-evaluated sequence of calls, performance may drop significantly, if the caller was so unlucky to strike that use case. That is why the constraint, and the corresponding structural unit test. As I pointed out already, no behavior unit test can see that issue coming.

    • @PedroPabloCalvoMorcillo
      @PedroPabloCalvoMorcillo ปีที่แล้ว +2

      @@zoran-horvatWhat an awesome answer! Thank you for your help. It's very instructive.

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว +4

      @@PedroPabloCalvoMorcillo I'm not judging you for not being aware of this - this is the rare topic in literature and programmers can't see its application. It is the SRP applied to tests.

  • @davidghydeable
    @davidghydeable ปีที่แล้ว

    Thank you. One little question not directly related to the subject (sorry!). Should you have called FlattenParallel() and Purge() after ToList() to prevent multiple enumeration of IEnumerable?

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว +2

      The call to ToList is required for the subsequent list pattern matching expressions. The code would not compule otherwise.
      However, there is the hidden optimization there - the private constructor (if ever called) receives the List argument. Therefore, that list construction will be the only one to execute.
      Please note that list patterns in the switch expression will not enumerate the list. They have other means to accomplish their goals.

  • @XtroTheArctic
    @XtroTheArctic ปีที่แล้ว