如何测试 playframework 的标签以及我需要这样做吗
当我创建新的 playframewor 的标签时。我需要对此进行测试吗(假设我们使用 TDD)?一般来说,对标签进行测试的最佳实践是什么?
例如,有一段代码,我使用我的标签“my_tag”:
#{my_tag param1:value1, param2:value2 }
如果稍微考虑一下标签..它只是在页面上呈现要使用的内容的演示文稿。那么我们应该测试它如何处理参数以及如何将其渲染为html?
When I create new playframewor's tag. Do I need make test for that (assuming that we use TDD)? And how it is possible and what it the best practice doing tests for tags in general?
For example there is a piece of code where I use my tag "my_tag":
#{my_tag param1:value1, param2:value2 }
If think about tag a little.. it is just piece of presentation that renders something on the page that would use. Then we should test how it handle parameters and how it render it to html?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
my_tag
是如何实现的?作为 html/tag 文件还是作为 FastTag 的代码?如果 my_tag 是在 html/tag 文件中定义的,一般指导是您不想在其中放入大量逻辑。因此,也许您会更好地测试/验证 value1 和 value2 的来源,并确保 my_tag 永远不会得到错误的 value1 或 value2 (假设您对谁在使用 my_tag 有相当严格的控制。
如果 my_tag 在代码中实现为 FastTag,那么代码可以像您想要的那样复杂,在这种情况下,您可能希望编写测试来执行 FastTag 逻辑中的所有执行路径,您只需使用一个测试页面即可做到这一点:
测试尽可能多的快乐和悲伤路径 。 my_tag 尽你所能。
How is
my_tag
implemented? As an html/tag file or in code as a FastTag?If my_tag is defined in an html/tag file the general guidance is you don't want to put a lot of logic in them. So maybe you would be better testing/validating the source of value1 and value2 and making sure my_tag never gets a bad value1 or value2 (assuming you have pretty tight control of who is using my_tag.
If my_tag is implemented in code as a FastTag, that code can be as complex as you want. In that case, you would want to write tests that exercise all the execution paths in the FastTag logic. You could do that just having a test page of:
to test as many happy and sad paths for my_tag as you can.