Why do we create unit tests?
Submitted by Mike Kelly on Fri, 19/11/2004 - 16:50.
unit testing
[textile]
A
friend of mine asked me the question: "Why do we create, validate and
peer-review unit test scripts?"
I was not sure how to answer this, so I took a look at some of the
work/thoughts of people smarter then me (James Bach, Brian Marick, Cem
Kaner, Jonathan Kohl, Bret Pettichord, Rex Black, Dave Liebreich) and I
added my own thoughts and experiences. The following is what I sent her
- along with some links to some good books and websites on the topic.
There are two main contexts from which I can answer this question. The
first is through the context of the software development lifecycle
(SDLC) and the second is from the context of the unit test itself, as
an individual unit of work in the overall testing effort for the
project. That is, when looking at the SDLC, unit testing can sometimes
involve a methodology - as in test driven development (TDD) typically
used in extreme or agile programming - or a unit test can sometimes be
used as a closing artifact for a phase - as in a regulated waterfall
methodology. When looking at a unit test as an individual unit or part
- under the overall testing process - it can be easier to see its value
outside of the implications it has on the SDLC in which it is being
utilized. I will answer this question from the context of the latter,
looking at a unit test as an individual work effort within the overall
software testing process.
Unit tests are typically created for the following reasons:
- Unit tests provide quick feedback to the developer.The
sooner a developer receives feedback on their code the sooner they can
implement a change based on that feedback. The unit test provides
feedback to the developer before other test systems exist for the code
under development and provides feedback in the code environment closest
to the developer. It is less expensive to fix errors found in a
development environment then errors promoted to test environments. It
is less expensive to fix errors found by the developer writing the code
then when the error is found and recorded by a tester. The time to
record, process, and track the error becomes overhead on the project.
- Unit tests provide a measure of developer progress.
There is an increasing belief is that a properly structured system is
easy to unit test. A unit test that is desirable but may be hard to
implement is seen as a sign that the system needs improving. Often,
developing unit tests will help focus and clarify thoughts on the code
being developed by forcing issues and ambiguities to the surface before
implementation and release.
- Unit tests mitigate concerns about the effects of refactoring.
Unit tests are typically written at the time of the highest flux and
least reliability in the code they are testing. By providing quick
feedback and providing a measure of progress, developers can work
confidently during times of flux and make changes with confidence,
knowing that any omissions or new errors introduced should be caught by
their suite of unit tests.
- Unit tests validate code integration.
Unit tests can be reused during code integration to ensure that changes
in other developer's code do not adversely affect the code tested via
the unit test. "If it worked before it should work now." While
typically not a complete test of integration, a complete test of all
the parts of a whole is the logical first step in testing the whole.
- Unit tests result in more testable code.In the process
of developing unit tests, developers typically a required to build in
test harnesses, logging and debug utilities, and APIs to exercise
functionality in isolation. Almost always, this functionality can be
used downstream in the testing process during integration testing,
system testing, regression testing, performance testing, and user
acceptance testing.
- Unit tests document the code they test.Unit tests can
be used as a form of executable documentation for the code they test.
These tests are of substantial value for programmers doing maintenance:
for both programmers trying to understand their own code at a later
date and when looking at someone else's code. The simplicity of unit
tests clarifies the intent and the expectations of the code.
- Unit tests are inexpensive to run and maintain.Relative
to all the other types of testing, unit tests are inexpensive to
create, maintain and run. Tools are typically free or included in the
enterprise IDE being utilized, resulting in no additional tool
investment. Unit tests are typically coded in the same language as the
code they are testing, resulting in no additional cost associated with
maintaining a specific language skill set. Unit tests are typically
simple enough that no extra documentation is necessary for their
longevity, unlike all other types of tests (with the exception of
exploratory testing).
- Unit tests report serious problems.For a good many
unit tests, failure would indicate a very serious problem if it were to
occur. Unlike system tests, with can involve subjectivity and
ambiguity, unit tests typically focus on technology issues and coding
errors.
Aside from their immediate value to the developers, as shown above, unit tests provide value to the overall testing process:
- Unit tests create a test harness that can be leveraged for other types of testing.As
described above under "Unit tests result in more testable code," unit
tests and unit test harnesses can be leveraged elsewhere. Unit tests
can be repurposed to address risks that may not have been envisioned
when they were written. Unit test can be used as a starting point for
APIs used for test automation. They can be used to seed a suite of
automated tests. Logs developed for unit testing can be leveraged
throughout the test lifecycle.
- Unit tests reduce the overall scope (coverage analysis and risk analysis) of other types of testing.
System tests can be designed by reviewing the existing unit tests, and
in some cases tapping into interfaces the developers had written for
their own tests, and can focus on efforts that the developers didn't
focus on. The system testers should take advantage of unit tests and
design their own tests to mitigate risks not already addressed by the
unit tests.
- Good unit tests remove the necessity of in-depth domain testing.With
the exception of a quick sampling to verify that the right testing was
done at the unit level, domain testing can be omitted entirely.
- Good unit tests remove the necessity of in-depth boundary value analysis.
With the exception of a quick sampling to verify that the right testing
was done at the unit level, boundary value analysis can be omitted
entirely.
http://www.testingreflections.com/node/view/1123
分享到:
相关推荐
标题中的“Download netcoreapp2.0 unit tests sample”指的是下载一个基于.NET Core 2.0版本的单元测试示例项目。这个项目是为了演示如何在ASP.NET Core MVC应用程序中进行单元测试,它与.NET Core 2.0框架兼容,这...
前端开源库-node-module-with-unittests-template带有UnitTests模板的节点模块、带有UnitTests模板的节点模块:带有UnitTests和覆盖率报告的通用节点模块的模板
Most popular Mocking framework for unit tests written in Java
《bloody-unit-tests:高效单元测试的实用工具》 在软件开发过程中,单元测试是确保代码质量、可维护性和稳定性的重要环节。"bloody-unit-tests"项目正是一款专注于创建单元测试模板的工具,专为.NET开发者设计,...
《NXP i.MX6ULL官方测试工具:unit_tests.zip深度解析》 在嵌入式系统开发领域,NXP的i.MX6ULL处理器因其高效能、低功耗的特性而备受青睐。为了帮助开发者更好地理解和调试这款处理器,NXP官方提供了一套名为“unit...
标签:activemq-unit-tests-5.9.1-tests.jar,activemq,unit,tests,5.9.1,tests,jar包下载,依赖包
标签:activemq-unit-tests-5.9.0-tests.jar,activemq,unit,tests,5.9.0,tests,jar包下载,依赖包
标签:activemq-unit-tests-5.10.0-tests.jar,activemq,unit,tests,5.10.0,tests,jar包下载,依赖包
标签:activemq-unit-tests-5.8.0-tests.jar,activemq,unit,tests,5.8.0,tests,jar包下载,依赖包
通过"Add" -> "Unit Test…"的方式创建一个单元测试文件,这将激活"Create Unit Tests…"菜单。 一旦这些步骤完成,你就可以在任何需要创建单元测试的方法上右键点击,选择"Create Unit Tests…",Visual Studio ...
sap press doc 解压密码:abap_developer
本单元的教学目标分为两个方面:一是学会用英语讨论学习方法,如"How do you study for tests?"(你是如何为考试学习的?),并找出适合自己的学习方法;二是理解和运用特定的语言结构,如动词+by/with gerund的表达...
欢迎来到kvm-unit-tests 有关此项目的高级描述,以及运行测试和添加测试HOWTO,请参见 。 建立测试 该目录包含KVM测试套件的源。 要创建测试图像,请执行以下操作: ./configure make 在此目录中。 测试图像在./...
《tpDcc-libs-unittests:Python中的DCC无关单元测试库》 在软件开发过程中,单元测试是一项至关重要的任务,它确保了代码的健壮性和可维护性。tpDcc-libs-unittests是一个专门针对DCC(Digital Content Creation,...
标签:activemq-unit-tests-5.10.0.jar,activemq,unit,tests,5.10.0,jar包下载,依赖包
标签:activemq-unit-tests-5.9.0.jar,activemq,unit,tests,5.9.0,jar包下载,依赖包
标签:activemq-unit-tests-5.9.1.jar,activemq,unit,tests,5.9.1,jar包下载,依赖包
标签:activemq-unit-tests-5.8.0.jar,activemq,unit,tests,5.8.0,jar包下载,依赖包
标签:activemq-unit-tests-5.9.0-sources.jar,activemq,unit,tests,5.9.0,sources,jar包下载,依赖包