单元测试:初学者问题 [英] Unit Testing: Beginner Questions

查看:24
本文介绍了单元测试:初学者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于开始进行单元测试了,我知道我应该这样做一段时间,但我有几个问题:

I'm finally starting out with unit testing, having known that I should be doing it for a while, but I have a few questions:

  • 我应该或不应该重新测试父母测试孩子时的课程,如果没有方法被覆盖?
  • 从概念上讲,您如何测试提交了表格的一部分?我正在使用PHP.(编辑:我问这个的原因是我有一个高级表单类,它生成一个表单,验证它,过滤它,并通过将类似 JSON 的数组作为输入和生成任何错误消息委派给各种较小的班级.但是,我无法在不提交表单的情况下测试错误等.编辑: 看起来可能是一个答案.)
  • 如果你有一个可选参数方法,你应该为当他们在场时和他们不是?
  • 是否应该以任何方式进行单元测试结合测试代码执行时间还是应该完全保留分开?
  • 是否有任何正当理由不运行每次都是完整的测试套件?
  • 就这样我得到了我的术语对,单位是什么单位测试参考?班级正在测试?方法?参数?还有什么?
  • Should or shouldn't I retest parent classes when testing the children if no methods have been overwritten?
  • Conceptually, how do you test the submitted part of a form? I'm using PHP. (Edit: The reason I ask this is that I have a high level form class that generates a form, validates it, filters it, and generates any error messages by taking a JSON-like array as input and delegating to a variety of smaller classes. However, I can't test the errors, etc without submitting the form. Edit: This looks like it might be an answer.)
  • If you have optional parameter in a method, should you write a test for both when they are present and when they are not?
  • Should unit testing in any way be combined with testing code execution time or should they remain completely separate?
  • Is there any valid reason not to run your full test suite every time?
  • Just so I'm getting my terminology right, to what does the unit in unit testing refer? The class being tested? The method? The parameter? Something else?

推荐答案

  • 测试父级,测试子级;如果孩子没有覆盖父方法,则无需重新测试.
  • 我不确定我是否理解第二个.您可以使用 Selenium 自动测试表单.这是你的意思吗?
  • 测试应包括快乐路径"和所有边缘情况.如果您有可选参数,请编写测试以显示值存在和不存在时的正确操作.
  • 单元测试、集成测试、验收测试、负载测试都是不同的想法,可能会有一些重叠.
  • 我敢打赌有正当理由,但如果您正在执行自动运行测试套件的自动化构建,为什么不运行它们?也许我会想到长时间运行,但这是我能想到的唯一原因.价值在于看到所有这些都继续通过,并且您所做的更改没有破坏任何东西.
  • 对我来说,单元测试意味着您正在测试的类,它可以有多种方法.我将它们与类联系起来,而不是形式.表单对我来说意味着界面和集成测试.
  • 这篇关于单元测试:初学者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆