使用JUNIT但不用于测试?
我有一个带有Vaadin的Spring Boot应用程序,我只需要简单的UI元素验证而无需备份BEAN。例如,仅检查TextField值是否为空,是否为空。
由于验证者需要一个bean,因此我正在考虑将Junit断言用于这项简单的工作。因此,不仅将JUNIT用于运行测试,还用于应用程序的主要流程。
这是好的做法,还有什么选择?
I have a spring boot application with Vaadin and I just need simple UI element validation without backing beans.For example to just check if a textfield value is null,empty or not.
Since validators require a bean I was thinking of using Junit Assert for this simple job. So using Junit not just for running tests but for the main flow of the application.
Is this good practice and what alternatives are there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于您需要将vaadin的转换器或验证器绑定到单个字段/值对的情况下,我已经写了 fieldBinder 实用程序类,可以在vaadin的目录中找到,并添加为对项目的Maven依赖性。
https://vaadin.com/directory/component/component/fieldbinds/fieldbinder
For such use cases where you need to bind Vaadin's Converters or Validators to a single field / value pair without a Bean being involved I have written FieldBinder utility class, which can be found in Vaadin's Directory and added as maven dependency to your project.
https://vaadin.com/directory/component/fieldbinder
不是 junit 是否要在生产代码中使用
仍然可以使用绑定的API,只忽略Getters/setters:
I don't think junit is meant to be used in a production code
I believe you can still use the binding API, just ignore getters/setters:
虽然
binder需要“ bean”
不必是一个完全抽出的东西。您还可以使用两个功能
绑定
(avalueProvider
和setter
)。因此,您基本上可以使用任何容器您喜欢作为“ bean”。例如a
地图
或atomicInteger
(您必须具有从中读取值并回写值的手段)。
While a "bean" is needed for the
Binder
it does not have to bea something fully drawn out. You can also
bind
with two functions (aValueProvider
and aSetter
). With this you can basically use anycontainer you like as "bean". E.g. a
Map
or anAtomicInteger
(youmust have means to read a value from it and write a value back).