0

In front-end projects(made in frameworks like Angular or React), when we correctly encapsulate complex functionalities, the components that really have some relation to the business logic normally became simple as a Form with default validations provided by the framework(or lib).

So, does unit test as "testing if wrong input to the form prevents submission", "if correct input makes submission allowed" really have value? Testing if the validation of those components works wouldn't be the same as testing the Form library (or the framework in the Angular case) instead?

2

2 Answers 2

3

Does worth testing simple details?

Maybe?

I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence -- Kent Beck, 2008

Within the context of Test Driven Development, "programmer tests" are motivated by analysis and design, not by validation (see Aim, Fire -- Beck, 2001).

For code that is "so simple that there are obviously no deficiencies", creating a bunch of tests is an investment that you may want to defer until you discover that further complexity is required.

If you are aware of the gap between decision and feedback during programming, and you are using appropriate techniques to control that gap, then you are doing TDD "the right way", even if the appropriate technique that you use isn't an automated check. (Note: this is from Test Driven Development by Example, the same source that says we should write a failing automated test before we write any code. Mixed signals are mixed.)


If you are considering tests for validation, then the considerations are a little different. Ultimately, we (not the authors of the form library or the framework) are answerable to our customers/goal donor/gold owner. So we need to understand what risks we are trying to mitigate, what mitigation strategies are available, and which of those strategies offers the best combination of trade offs.

1
  • 1
    A fitting quote by Kent Beck, considering he's the one who invented Test-Driven Development. Commented Apr 25, 2022 at 12:51
2

Every unit of implementation code is an asset. Every unit test is a line in your insurance policy.

You get to decide which assets are protected and how exactly how they're fixed or replaced when they break.

  1. How valuable is the asset?
  2. How much is it worth paying for them in your insurance policy?
  3. When the asset breaks, what exactly is the required remedy to keep the business happy?

Not the answer you're looking for? Browse other questions tagged or ask your own question.