Servlet单元测试(Servlet unit test)
目前我使用TestNG框架来测试应用程序业务逻辑,最近我添加了一些Servlet类。
如何在TestNg框架中单元测试这些Servlet类?
Currently I'm using TestNG framework for testing application business logic, i added some Servlet classes recently.
How do I unit test these Servlet classes in TestNg framework?
原文:https://stackoverflow.com/questions/2570875
最满意答案
在完成翻译器组件的代码之后,我不明白为什么这不起作用。
最后,这就是我所做的:
- 从3.0.2升级到3.1.3
- 删除了我的表单类中的组件转换器的instanciation
- 在我的表单类(声明为服务)中注入转换器组件
site.type.book:class:AppBundle \ Form \ BookType标签: - {name:form.type}参数:['@ doctrine','@ request_stack','@ logger','@ transnslator']
After walking through the code of the translator component, I didn't understand why this is not working.
Finally, this is what I did:
- Upgrading from 3.0.2 to 3.1.3
- Removed the instanciation of the component translator in my form class
- Injected the translator component in my form class (which is declared as a service)
site.type.book: class: AppBundle\Form\BookType tags: - { name: form.type } arguments: ['@doctrine', '@request_stack', '@logger', '@translator']
相关问答
更多-
这是因为Symfony Controller“createForm”辅助方法的工作原理。 推理背后的原因是多个表单可能具有相同的目标URL。 通过以表单名称作为前缀,Symfony可以知道提交了哪个表单。 这可以通过查看“createForm”方法实现来看出: public function createForm($type, $data = null, array $options = array()) { return $this->container->get('form.factory')- ...
-
将数据传递到Symfony 2.8 / 3.0中的buildForm()(Passing data to buildForm() in Symfony 2.8, 3.0 and above)[2022-03-16]
这也打破了我们的一些形式。 我通过选择解析器传递自定义数据来修复它。 在您的表单类型: public function buildForm(FormBuilderInterface $builder, array $options) { $this->traitChoices = $options['trait_choices']; $builder ->add('name', TextType::class, ['label' => 'L_PROFILE_EDIT_NAM ... -
FormBuilder不应该操纵实体数据,因为正如其名称所示,它的作用是构建Form的不同字段。 关于填充字段,实际上非常简单:如果在实体上设置属性,当您将实体绑定到Form ,相关字段(即与您的属性同名的字段)将使其数据充分更改。 示例: FooType.php public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('title', 'text'); } ...
-
Symfony 3 Formtype子不会返回相同的块前缀(Symfony 3 Formtype child doesn't return the same block prefix)[2022-07-03]
您可以使用窗体事件来修改窗体,而不是使用子窗体。 use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; class AdvertType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) ... -
升级到Symfony 3后,自定义的FormType出现问题(After upgrading to Symfony 3 a custom FormType gives problems)[2023-08-20]
我发现了这个问题。 在MapType :: configureOptions()中,当它应该是'data_class' => 'LocationBundle\Entity\Location'时,我定义了'data_class' => LocationType::class 。 将代码转换为Symfony3规则时必然发生。 我把这个问题留给别人......也许甚至是我自己。 I found the problem. In MapType::configureOptions() I defined 'data_ ... -
我刚刚发现在symfony2 console命令中,从不使用config.yml定义的默认语言环境,因此语言环境为NULL 。 因此,翻译人员永远不会使用任何可用的翻译区域设置。 这就是翻译键完整而不是翻译的原因。 当我只运行试图翻译某些内容的控制台命令时,我得到了这个提示,但是没有生成app / cache / dev / translations文件夹中的目录。 所以,这就是我在控制台命令工作中进行翻译的方式(在我的例子中,我将其设置为id_ID): $translator = $this->getCo ...
-
您可以使用jquery库更简单一点: 首先,我们使用choice_attr选项更改构建器以将地点类型id渲染到
-
在完成翻译器组件的代码之后,我不明白为什么这不起作用。 最后,这就是我所做的: 从3.0.2升级到3.1.3 删除了我的表单类中的组件转换器的instanciation 在我的表单类(声明为服务)中注入转换器组件 site.type.book:class:AppBundle \ Form \ BookType标签: - {name:form.type}参数:['@ doctrine','@ request_stack','@ logger','@ transnslator'] After walking t ...
-
Symfony 3.0 - 不根据setLocale()进行翻译(Symfony 3.0 - not translating according to setLocale())[2022-08-12]
我最终创建了一个localeListener,它在控制器中设置语言环境时设置会话中的语言环境,如$request->setLocale('fr') 。 现在我的文本在相应的语言环境中被翻译,但仅在额外的页面刷新之后才开始。 namespace SiteBundle\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use ... -
FormType验证symfony2(FormType Validation symfony2)[2022-04-14]
在你的行中: ->add('email', 'email', array( new NotBlank() ) ) 您传入new NotBlank() ,但它应该在约束选项中: ->add('email', 'email', array( 'constraints' => array( new NotBlank() ) ) ) In your lines: ->add('em ...