Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Unit testing
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Value == Unit testing is intended to ensure that the units meet their [[Software design|design]] and behave as intended.<ref name="hamill">{{cite book |last1=Hamill |first1=Paul |title=Unit Test Frameworks: Tools for High-Quality Software Development |date=2004 |publisher=O'Reilly Media, Inc.|isbn=9780596552817 |url=https://books.google.com/books?id=2ksvdhhnWQsC}}</ref> By writing tests first for the smallest testable units, then the compound behaviors between those, one can build up comprehensive tests for complex applications.<ref name="hamill" /> One goal of unit testing is to isolate each part of the program and show that the individual parts are correct.<ref name="kolawa"/> A unit test provides a strict, written [[Design by Contract|contract]] that the piece of code must satisfy. === Early detection of problems in the development cycle === Unit testing finds problems early in the [[development cycle]]. This includes both bugs in the programmer's implementation and flaws or missing parts of the specification for the unit. The process of writing a thorough set of tests forces the author to think through inputs, outputs, and error conditions, and thus more crisply define the unit's desired behavior.{{cn|date=November 2023}} === Reduced cost === The cost of finding a bug before coding begins or when the code is first written is considerably lower than the cost of detecting, identifying, and correcting the bug later. Bugs in released code may also cause costly problems for the end-users of the software.<ref>{{cite journal |last1=Boehm |first1=Barry W. |author-link1=Barry Boehm |last2=Papaccio |first2=Philip N. |date=October 1988 |title=Understanding and Controlling Software Costs |url=http://faculty.ksu.edu.sa/ghazy/Cost_MSc/R6.pdf |journal=IEEE Transactions on Software Engineering |volume=14 |issue=10 |pages=1462β1477 |doi=10.1109/32.6191 |access-date=13 May 2016 |archive-date=9 October 2016 |archive-url=https://web.archive.org/web/20161009084506/http://faculty.ksu.edu.sa/ghazy/Cost_MSc/R6.pdf |url-status=dead }}</ref><ref>{{cite web|url=https://msdn.microsoft.com/en-us/library/ee330950%28v=vs.110%29.aspx|title=Test Early and Often|publisher=Microsoft}}</ref><ref>{{cite web|url=http://www.ni.com/white-paper/8082/en/| title=Prove It Works: Using the Unit Test Framework for Software Testing and Validation| publisher=[[National Instruments]]| date=2017-08-21}}</ref> Code can be impossible or difficult to unit test if poorly written, thus unit testing can force developers to structure functions and objects in better ways. === More frequent releases === Unit testing enables more frequent releases in software development. By testing individual components in isolation, developers can quickly identify and address issues, leading to faster iteration and release cycles.<ref>{{cite web |last1=Erik |title=You Still Don't Know How to Do Unit Testing (and Your Secret is Safe with Me) |url=https://stackify.com/unit-testing-basics-best-practices/ |website=Stackify |date=10 March 2023 |access-date=10 March 2023}}</ref> === Allows for code refactoring === Unit testing allows the programmer to [[Refactoring|refactor]] code or upgrade system libraries at a later date, and make sure the module still works correctly (e.g., in [[regression testing]]). The procedure is to write test cases for all [[subroutine|function]]s and [[method (computer science)|method]]s so that whenever a change causes a fault, it can be identified quickly. === Detects changes which may break a design contract === Unit tests detect changes which may break a [[Design by contract|design contract]]. === Reduce uncertainty === Unit testing may reduce uncertainty in the units themselves and can be used in a [[Top-down and bottom-up design|bottom-up]] testing style approach. By testing the parts of a program first and then testing the sum of its parts, [[integration testing]] becomes much easier.{{Citation needed|date=January 2013}} === Documentation of system behavior === Some programmers contend that unit tests provide a form of documentation of the code. Developers wanting to learn what functionality is provided by a unit, and how to use it, can review the unit tests to gain an understanding of it.{{Citation needed|date=September 2019}} Test cases can embody characteristics that are critical to the success of the unit. These characteristics can indicate appropriate/inappropriate use of a unit as well as negative behaviors that are to be trapped by the unit. A test case documents these critical characteristics, although many software development environments do not rely solely upon code to document the product in development.{{Citation needed|date=September 2019}} In some processes, the act of writing tests and the code under test, plus associated refactoring, may take the place of formal design. Each unit test can be seen as a design element specifying classes, methods, and observable behavior.{{Citation needed|date=September 2019}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)