Unit tests for HTML Output?

后端 未结 9 1070
-上瘾入骨i
-上瘾入骨i 2021-02-19 00:39

This may be a dumb question, but do you make unit tests for the HTML output of your PHP functions/scripts?

I try to keep my HTML and my PHP separate - i.e. HTML includes

9条回答
  •  忘了有多久
    2021-02-19 01:20

    In some cases (such as CakePHP Helpers), the purpose of a class or function is to generate consistent HTML for you. In such cases, it's important to test that the expected properties of the generated unit of HTML are correct for given inputs. The question is definitely valid in that context.

    PHPUnit provides an assertTag() function for this purpose.

    However to echo the others; it's important to stress that unit testing should be done on the smallest possible components of your project, and not entire rendered web pages. There are other tools (Selenium for example) that are designed for ensuring that those individual components are integrated together properly.

提交回复
热议问题