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!
== Applications == === Extreme programming === Unit testing is the cornerstone of [[extreme programming]], which relies on an automated [[list of unit testing frameworks|unit testing framework]]. This automated unit testing framework can be either third party, e.g., [[xUnit]], or created within the development group. Extreme programming uses the creation of unit tests for [[test-driven development]]. The developer writes a unit test that exposes either a software requirement or a defect. This test will fail because either the requirement isn't implemented yet, or because it intentionally exposes a defect in the existing code. Then, the developer writes the simplest code to make the test, along with other tests, pass. Most code in a system is unit tested, but not necessarily all paths through the code. Extreme programming mandates a "test everything that can possibly break" strategy, over the traditional "test every execution path" method. This leads developers to develop fewer tests than classical methods, but this isn't really a problem, more a restatement of fact, as classical methods have rarely ever been followed methodically enough for all execution paths to have been thoroughly tested.{{Citation needed|date=November 2008}} Extreme programming simply recognizes that testing is rarely exhaustive (because it is often too expensive and time-consuming to be economically viable) and provides guidance on how to effectively focus limited resources. Crucially, the test code is considered a first class project artifact in that it is maintained at the same quality as the implementation code, with all duplication removed. Developers release unit testing code to the code repository in conjunction with the code it tests. Extreme programming's thorough unit testing allows the benefits mentioned above, such as simpler and more confident code development and [[refactoring]], simplified code integration, accurate documentation, and more modular designs. These unit tests are also constantly run as a form of [[regression test]]. Unit testing is also critical to the concept of [[Emergent Design]]. As emergent design is heavily dependent upon refactoring, unit tests are an integral component.{{cn|date=November 2023}} === Automated testing frameworks === An automated testing framework provides features for automating test execution and can accelerate writing and running tests. Frameworks have been developed for [[list of unit testing frameworks|a wide variety of programming languages]]. Generally, frameworks are [[Third-party software component|third-party]]; not distributed with a compiler or [[integrated development environment]] (IDE). Tests can be written without using a framework to exercise the code under test using [[Assertion (software development)|assertions]], [[exception handling]], and other [[control flow]] mechanisms to verify behavior and report failure. Some note that testing without a framework is valuable since there is a [[barrier to entry]] for the adoption of a framework; that having some tests is better than none, but once a framework is in place, adding tests can be easier.<ref>{{cite web|url=http://www.bullseye.com/coverage.html|access-date=24 March 2009|title=Intermediate Coverage Goals|author=Bullseye Testing Technology|date=2006β2008}}</ref> In some frameworks advanced test features are missing and must be hand-coded. === Language-level unit testing support === Some programming languages directly support unit testing. Their grammar allows the direct declaration of unit tests without importing a library (whether third party or standard). Additionally, the Boolean conditions of the unit tests can be expressed in the same syntax as Boolean expressions used in non-unit test code, such as what is used for {{code| lang = java |if}} and {{code| lang = java |while}} statements. Languages with built-in unit testing support include: {{colbegin|colwidth=20em}} * [[Cobra (programming language)|Cobra]] * [[D (programming language)|D]]<ref>{{cite web|title=Unit Tests - D Programming Language|url=http://dlang.org/spec/unittest.html|website=D Programming Language|publisher=D Language Foundation|access-date=5 August 2017}}</ref> * [[Rust (programming language)|Rust]]<ref>{{cite web|url=https://doc.rust-lang.org/book/ch11-01-writing-tests.html|access-date=21 August 2023|title=How to Write Tests|author=Steve Klabnik and Carol Nichols, with contributions from the Rust Community|date=2015β2023}}</ref> {{colend}} Languages with standard unit testing framework support include: {{colbegin|colwidth=20em}} * [[Apex (programming language)|Apex]] * [[Crystal (programming language)|Crystal]]<ref>{{cite web|url=https://crystal-lang.org/api/0.23.1/Spec.html|access-date=18 September 2017|title=Crystal Spec|publisher=crystal-lang.org}}</ref> * [[Erlang (programming language)|Erlang]] * [[Go (programming language)|Go]]<ref>{{cite web|url=http://golang.org/pkg/testing/|access-date=3 December 2013|title=testing - The Go Programming Language|publisher=golang.org}}</ref> * [[Julia (programming language)|Julia]]<ref>{{cite web|url=https://docs.julialang.org/en/v1/stdlib/Test/|title=Unit Testing Β· The Julia Language|access-date=2022-06-15|publisher=docs.julialang.org}}</ref> * [[LabVIEW]] * [[MATLAB]] * [[Python (programming language)|Python]]<ref>{{cite web|url=https://docs.python.org/3/library/unittest.html|access-date=18 April 2016|title=unittest -- Unit testing framework|author=Python Documentation|date=2016}}</ref> * [[Racket (programming language)|Racket]]<ref name=Racket_Unit_Testing>{{cite web|last1=Welsh|first1=Noel|last2=Culpepper|first2=Ryan|title=RackUnit: Unit Testing|url=http://docs.racket-lang.org/rackunit/index.html|publisher=PLT Design Inc.|access-date=26 February 2019|ref=Racket_Unit_Testing}}</ref><ref name=Racket_Unit_Testing_Main_dist>{{cite web|last1=Welsh|first1=Noel|last2=Culpepper|first2=Ryan|title=RackUnit Unit Testing package part of Racket main distribution|url=https://pkgs.racket-lang.org/package/rackunit|publisher=PLT Design Inc.|access-date=26 February 2019|ref=Racket_Unit_Testing_Main_dist}}</ref> * [[Ruby (programming language)|Ruby]]<ref>{{cite web|url=http://ruby-doc.org/stdlib-2.0.0/libdoc/minitest/rdoc/MiniTest.html|title=Minitest (Ruby 2.0)|publisher=Ruby-Doc.org}}</ref> * [[Swift (programming language)|Swift]] {{colend}} Some languages do not have built-in unit-testing support but have established unit testing libraries or frameworks. These languages include: {{colbegin|colwidth=20em}} * [[ABAP]] * [[C++]] * [[C Sharp (programming language)|C#]] * [[Clojure]]<ref name=Clojure_Unit_Testing_Framework>{{cite web|last1=Sierra|first1=Stuart|title=API for clojure.test - Clojure v1.6 (stable)|url=https://clojure.github.io/clojure/clojure.test-api.html|access-date=11 February 2015|ref=Clojure_Unit_Testing_Framework}}</ref> * [[Elixir (programming language)|Elixir]] * [[Java (programming language)|Java]] * [[JavaScript]] * [[Objective-C]] * [[Perl]] * [[PHP]] * [[Windows PowerShell|PowerShell]]<ref>{{cite web|url=https://github.com/pester/Pester|access-date=28 January 2016|title=Pester Framework|website=[[GitHub]]}}</ref> * [[R (programming language)|R]] with testthat * [[Scala (programming language)|Scala]] * [[tcl]] * [[Visual Basic .NET]] * [[Xojo]] with XojoUnit {{colend}}
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)