Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I test my HTMLHelpers?

Is there any tangible value in unit testing your own htmlhelpers? Many of these things just spit out a bunch of html markup - there's little if no logic. So, do you just compare one big html string to another? I mean, some of these thing require you to look at the generated markup in a browser to verify it's the output you want.

Seems a little pointless.

like image 851
Saraz Avatar asked Nov 05 '22 08:11

Saraz


1 Answers

Yes.

While there may be little to no logic now, that doesn't mean that there isn't going to be more logic added down the road. When that logic is added, you want to be sure that it doesn't break the existing functionality.

That's one of the reasons that Unit Tests are written.

If you're following Test Driven Development, you write the test first and then write the code to satisfy test.

That's another reason.

You also want to make sure you identify and test any possible edge cases with your Helper (like un-escaped HTML literals, un-encoded special characters, etc).

like image 59
Justin Niessner Avatar answered Nov 10 '22 19:11

Justin Niessner