单元测试入门 [英] Getting Started with Unit Testing

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

问题描述

单元测试,粗略地说,就是用测试代码孤立地测试你的代码.想到的直接优势是:

Unit testing is, roughly speaking, testing bits of your code in isolation with test code. The immediate advantages that come to mind are:

  • 运行测试变得可自动化且可重复
  • 与通过 GUI 进行的点击式测试相比,您可以进行更精细的测试

Rytmis

我的问题是,当前的最佳实践"是什么?在工具方面以及何时何地使用单元测试作为日常编码的一部分?

My question is, what are the current "best practices" in terms of tools as well as when and where to use unit testing as part of your daily coding?

让我们尝试在某种程度上与语言无关并涵盖所有基础.

Lets try to be somewhat language agnostic and cover all the bases.

推荐答案

好吧,这里有一些最佳实践,来自一个没有进行单元测试的人......咳咳.

Ok here's some best practices from some one who doesn't unit test as much as he should...cough.

  1. 确保您的测试测试one一件事,只有一件事.
  2. 随时编写单元测试.最好在之前编写要测试的代码.
  3. 不要对 GUI 进行单元测试.
  4. 分离您的关注点.
  5. 尽量减少测试的依赖.
  6. 使用模拟模拟行为.
  1. Make sure your tests test one thing and one thing only.
  2. Write unit tests as you go. Preferably before you write the code you are testing against.
  3. Do not unit test the GUI.
  4. Separate your concerns.
  5. Minimise the dependencies of your tests.
  6. Mock behviour with mocks.

这篇关于单元测试入门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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