-
We have a partial class which contains the code for the Blazor view. In it we have collections with items which we display in the view. The collections are protected properties and are used only in the view. What is the right way to test them? Should we just get the markup where they are rendered and check that it contains the necessary information? Or should we try to extract them in some way from the component? eg:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @MiBuena, This is less of a bUnit question and more a question of testing strategy in general. My gut feeling is that if something is non-public, its an implementation detail that you should not be writing your tests against. If you do, you tie your tests very tightly to an implementation detail that you might want to change later without breaking your tests. Internal refactoring of a component under test that does NOT change its output or observable behavior should no be breaking tests. If it is an important business requirement that the If this is indeed an implementation detail, I would use the one of approaches described on https://bunit.egilhansen.com/docs/verification/verify-markup to verify that the component renders the appropriate markup for the input. Hope this helps, Egil. |
Beta Was this translation helpful? Give feedback.
Hi @MiBuena,
This is less of a bUnit question and more a question of testing strategy in general.
My gut feeling is that if something is non-public, its an implementation detail that you should not be writing your tests against. If you do, you tie your tests very tightly to an implementation detail that you might want to change later without breaking your tests. Internal refactoring of a component under test that does NOT change its output or observable behavior should no be breaking tests.
If it is an important business requirement that the
Items
list contains certain items, I would instead ask why it is protected in the first place? If it is important, then it likely also needs to be pu…