<i id='qlXOL'><tr id='qlXOL'><dt id='qlXOL'><q id='qlXOL'><span id='qlXOL'><b id='qlXOL'><form id='qlXOL'><ins id='qlXOL'></ins><ul id='qlXOL'></ul><sub id='qlXOL'></sub></form><legend id='qlXOL'></legend><bdo id='qlXOL'><pre id='qlXOL'><center id='qlXOL'></center></pre></bdo></b><th id='qlXOL'></th></span></q></dt></tr></i><div id='qlXOL'><tfoot id='qlXOL'></tfoot><dl id='qlXOL'><fieldset id='qlXOL'></fieldset></dl></div>
      • <bdo id='qlXOL'></bdo><ul id='qlXOL'></ul>
    1. <tfoot id='qlXOL'></tfoot>
      <legend id='qlXOL'><style id='qlXOL'><dir id='qlXOL'><q id='qlXOL'></q></dir></style></legend>

      <small id='qlXOL'></small><noframes id='qlXOL'>

      1. 在 Spring MVC 中具有基于注释的验证的单元测试表

        时间:2023-09-28
        <tfoot id='d5wZJ'></tfoot>

        1. <i id='d5wZJ'><tr id='d5wZJ'><dt id='d5wZJ'><q id='d5wZJ'><span id='d5wZJ'><b id='d5wZJ'><form id='d5wZJ'><ins id='d5wZJ'></ins><ul id='d5wZJ'></ul><sub id='d5wZJ'></sub></form><legend id='d5wZJ'></legend><bdo id='d5wZJ'><pre id='d5wZJ'><center id='d5wZJ'></center></pre></bdo></b><th id='d5wZJ'></th></span></q></dt></tr></i><div id='d5wZJ'><tfoot id='d5wZJ'></tfoot><dl id='d5wZJ'><fieldset id='d5wZJ'></fieldset></dl></div>
            <tbody id='d5wZJ'></tbody>
          <legend id='d5wZJ'><style id='d5wZJ'><dir id='d5wZJ'><q id='d5wZJ'></q></dir></style></legend>
          • <small id='d5wZJ'></small><noframes id='d5wZJ'>

                <bdo id='d5wZJ'></bdo><ul id='d5wZJ'></ul>

                • 本文介绍了在 Spring MVC 中具有基于注释的验证的单元测试表单 bean 的良好模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在对表单 bean 使用基于注释的验证时,对这些 bean 进行单元测试以确保为每个字段指定正确的验证注释的最佳实践是什么?

                  When using annotation based validation for a form bean, what is the best practice for unit-testing those beans in order to ensure that correct validations annotations are specified for each field?

                  例如,如果您有:

                  public class MyForm {
                      @NotNull
                      private String name;
                  }
                  

                  验证 @NotNull 是否应用于它的最佳方法是什么?

                  What is the best way to verify that @NotNull is applied to it?

                  一个明显的方法是创建一个验证器,向它抛出一个 null 并期望它失败.但在我看来,这不是最好的方法,因为您将使用它而不是信任框架来测试 @NotNull 的行为和实现.

                  One obvious way is to create a validator, throw a null at it and expect it to fail. But in my view this is not the best way as you'll be testing the behaviour and implementation of @NotNull using that rather than trusting the framework.

                  理想情况下,我希望使用反射或实用程序,让我可以断言 @NotNull(和任何其他)验证已应用于给定字段,而不必发送验证失败的各种值组合.

                  Ideally I would want to use reflection or a utility that gives me the possibility of just asserting that an @NotNull (and any other) validation is applied to a given field, rather than having to send various combination of values that fail validation.

                  有没有一种优雅的方法可以做到这一点,或者我总体上是在正确的轨道上吗?

                  Is there an elegant way of doing this, or am I on the right track in general?

                  推荐答案

                  您还可以为您的 Bean 编写单元测试,这些单元测试使用 JSR303 使用验证器工厂进行注释.参见示例:http://musingsofaprogrammingaddict.blogspot.com/2009/02/using-bean-validation-with-spring.html

                  You can also write unit tests for your Beans which are annotated usin JSR303 using validator factory. See example: http://musingsofaprogrammingaddict.blogspot.com/2009/02/using-bean-validation-with-spring.html

                  这篇关于在 Spring MVC 中具有基于注释的验证的单元测试表单 bean 的良好模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Spring 可以评估 SpEL 表达式中的所有字符/表达式, 下一篇:在JAVA中的注释内调用方法

                  相关文章

                  最新文章

                • <tfoot id='gQlCv'></tfoot>

                  1. <i id='gQlCv'><tr id='gQlCv'><dt id='gQlCv'><q id='gQlCv'><span id='gQlCv'><b id='gQlCv'><form id='gQlCv'><ins id='gQlCv'></ins><ul id='gQlCv'></ul><sub id='gQlCv'></sub></form><legend id='gQlCv'></legend><bdo id='gQlCv'><pre id='gQlCv'><center id='gQlCv'></center></pre></bdo></b><th id='gQlCv'></th></span></q></dt></tr></i><div id='gQlCv'><tfoot id='gQlCv'></tfoot><dl id='gQlCv'><fieldset id='gQlCv'></fieldset></dl></div>

                      <small id='gQlCv'></small><noframes id='gQlCv'>

                        <bdo id='gQlCv'></bdo><ul id='gQlCv'></ul>

                      <legend id='gQlCv'><style id='gQlCv'><dir id='gQlCv'><q id='gQlCv'></q></dir></style></legend>