A sanity check or sanity test is a basic test to quickly evaluate whether a claim or the result of a calculation can possibly be true. It is a simple check to see if the produced material is rational (that the material's creator was thinking rationally, applying
sanity). The point of a sanity test is to rule out certain classes of obviously false results, not to catch every possible error. A
rule-of-thumb or
back-of-the-envelope calculation
A back-of-the-envelope calculation is a rough calculation, typically jotted down on any available scrap of paper such as an envelope. It is more than a guess but less than an accurate calculation or mathematical proof. The defining characteristic o ...
may be checked to perform the test. The advantage of performing an initial sanity test is that of speedily evaluating basic function.
In arithmetic, for example, when multiplying by 9, using the
divisibility rule
A divisibility rule is a shorthand and useful way of determining whether a given integer is divisible by a fixed Divisor (number theory), divisor without performing the division, usually by examining its digits. Although there are divisibility test ...
for 9 to verify that the
sum of digits of the result is divisible by 9 is a sanity test—it will not catch ''every'' multiplication error, but is a quick and simple method to discover ''many'' possible errors.
In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, a ''sanity test'' is a very brief run-through of the functionality of a
computer program
A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
, system, calculation, or other analysis, to assure that part of the system or methodology works roughly as expected. This is often prior to a more exhaustive round of testing.
Use in different fields
Mathematical
A sanity test can refer to various
orders of magnitude
In a ratio scale based on powers of ten, the order of magnitude is a measure of the nearness of two figures. Two numbers are "within an order of magnitude" of each other if their ratio is between 1/10 and 10. In other words, the two numbers are wi ...
and other simple
rule-of-thumb devices applied to cross-check
mathematical
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
calculations
A calculation is a deliberate mathematical process that transforms a plurality of inputs into a singular or plurality of outputs, known also as a result or results. The term is used in a variety of senses, from the very definite arithmetical ...
. For example:
*If one were to attempt to
square
In geometry, a square is a regular polygon, regular quadrilateral. It has four straight sides of equal length and four equal angles. Squares are special cases of rectangles, which have four equal angles, and of rhombuses, which have four equal si ...
738 and calculated 54,464, a quick sanity check could show that this result cannot be true. Consider that yet Since squaring positive integers preserves their
inequality, the result cannot be true, and so the calculated result is incorrect. The correct answer, is more than 10 times higher than 54,464.
*In multiplication, is not 142,135 since 918 is divisible by three but 142,135 is not (digits add up to 16, not a
multiple of three). Also, the product must end in the same digit as the product of end-digits: but 142,135 does not end in "0" like "40", while the correct answer does: An even quicker check is that the product of even and odd numbers is even, whereas 142,135 is odd.
Physical
*
Dimensional analysis may be used as a sanity check of physical equations: the two sides of any equation must be commensurable or have the same dimensions. A person who has calculated the
power output of a
car
A car, or an automobile, is a motor vehicle with wheels. Most definitions of cars state that they run primarily on roads, seat one to eight people, have four wheels, and mainly transport people rather than cargo. There are around one billio ...
to be 700
kJ may have omitted a factor, since the unit ''joules'' is a measure of
energy
Energy () is the physical quantity, quantitative physical property, property that is transferred to a physical body, body or to a physical system, recognizable in the performance of Work (thermodynamics), work and in the form of heat and l ...
, not power (energy per unit time).
*When determining
physical properties
A physical property is any property of a physical system that is measurable. The changes in the physical properties of a system can be used to describe its changes between momentary states. A quantifiable physical property is called ''physical ...
, comparing to known or similar substances will often yield insight on whether the result is reasonable. For instance, most metals sink in water, so the
density
Density (volumetric mass density or specific mass) is the ratio of a substance's mass to its volume. The symbol most often used for density is ''ρ'' (the lower case Greek letter rho), although the Latin letter ''D'' (or ''d'') can also be u ...
of most metals should be greater than
that of water (~).
*
Fermi estimates will often provide insight on the order of magnitude of an expected value.
Software development
In software development, a sanity test (a form of
software testing
Software testing is the act of checking whether software satisfies expectations.
Software testing can provide objective, independent information about the Quality (business), quality of software and the risk of its failure to a User (computin ...
which offers "quick, broad, and shallow testing") evaluates the result of a subset of application functionality to determine whether it is possible and reasonable to proceed with further testing of the entire application. Sanity tests may sometimes be used interchangeably with
smoke tests insofar as both terms denote tests which determine whether it is ''possible'' and ''reasonable'' to continue testing further. On the other hand, a distinction is sometimes made that a smoke test is a non-exhaustive test that ascertains whether the most crucial functions of a programme work before proceeding with further testing whereas a sanity test refers to whether specific functionality such as a particular bug fix works as expected without testing the wider functionality of the software. In other words, a sanity test determines whether the intended result of a code change works correctly while a smoke test ensures that nothing else important was broken in the process. Sanity testing and smoke testing avoid wasting time and effort by quickly determining whether an application is too flawed to merit more rigorous
QA testing, but needs more developer
debugging
In engineering, debugging is the process of finding the Root cause analysis, root cause, workarounds, and possible fixes for bug (engineering), bugs.
For software, debugging tactics can involve interactive debugging, control flow analysis, Logf ...
.
Groups of sanity tests are often bundled together for automated
unit testing
Unit testing, component or module testing, is a form of software testing by which isolated source code is tested to validate expected behavior.
Unit testing describes tests that are run at the unit-level to contrast testing at the Integration ...
of functions, libraries, or applications prior to
merging development code into a testing or
trunk version control
branch
A branch, also called a ramus in botany, is a stem that grows off from another stem, or when structures like veins in leaves are divided into smaller veins.
History and etymology
In Old English, there are numerous words for branch, includ ...
, for
automated building, or for
continuous integration
Continuous integration (CI) is the practice of integrating source code changes frequently and ensuring that the integrated codebase is in a workable state.
Typically, developers Merge (version control), merge changes to an Branching (revisio ...
and
continuous deployment.
Another common usage of ''sanity test'' is to denote checks which are performed programme code, usually on arguments to functions or returns therefrom, to see if the answers can be assumed to be correct. The more complicated the routine, the more important that its response be checked. The trivial case is checking to see whether the
return value
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is sav ...
of a function indicated success or failure, and to therefore cease further processing upon failure. This return value is actually often itself the result of a sanity check. For example, if the function attempted to open, write to, and close a file, a sanity check may be used to ensure that it did not fail on any of these actions—which is a sanity check often ignored by programmers.
These kinds of sanity checks may be used during development for debugging purposes and also to aid in
troubleshooting software
runtime errors
Execution in computer and software engineering is the process by which a computer or virtual machine interprets and acts on the instructions of a computer program. Each instruction of a program is a description of a particular action which must b ...
. For example, in a bank account management application, a sanity check will fail if a withdrawal requests more money than the total account balance rather than allowing the account to go negative (which wouldn't be sane). Another sanity test might be that deposits or purchases correspond to patterns established by historical data—for example, large purchase transactions or ATM withdrawals in foreign locations never before visited by the cardholder may be flagged for confirmation.
Sanity checks are also performed upon installation of
stable, production software code into a new computing
environment to ensure that all
dependencies are met, such as a compatible
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
and
link libraries
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
. When a computing environment has passed all the sanity checks, it's known as a sane environment for the installation programme to proceed with reasonable expectation of success.
A
"Hello, World!" program
A "Hello, World!" program is usually a simple computer program that emits (or displays) to the screen (often the Console application, console) a message similar to "Hello, World!". A small piece of code in most general-purpose programming languag ...
is often used as a sanity test for a
development environment similarly. Rather than a complicated script running a set of unit tests, if this simple programme fails to compile or execute, it proves that the supporting environment likely has a configuration problem that will prevent ''any'' code from compiling or executing. But if "Hello world" executes, then any problems experienced with other programmes likely can be attributed to errors in that application's code rather than the environment.
The
Association for Computing Machinery
The Association for Computing Machinery (ACM) is a US-based international learned society for computing. It was founded in 1947 and is the world's largest scientific and educational computing society. The ACM is a non-profit professional membe ...
, and software projects such as
Android,
MediaWiki
MediaWiki is free and open-source wiki software originally developed by Magnus Manske for use on Wikipedia on January 25, 2002, and further improved by Lee Daniel Crocker,mailarchive:wikipedia-l/2001-August/000382.html, Magnus Manske's announc ...
and
Twitter
Twitter, officially known as X since 2023, is an American microblogging and social networking service. It is one of the world's largest social media platforms and one of the most-visited websites. Users can share short text messages, image ...
,
discourage use of the phrase ''sanity check'' in favour of other terms such as ''confidence test'', ''coherence check'', or simply ''test'', as part of a wider attempt to avoid
ableist language and increase
inclusivity.
See also
*
Certifying algorithm
*
Checksum
A checksum is a small-sized block of data derived from another block of digital data for the purpose of detecting errors that may have been introduced during its transmission or storage. By themselves, checksums are often used to verify dat ...
*
Fermi problem
A Fermi problem (or Fermi question, Fermi quiz), also known as an order-of-magnitude problem, is an estimation problem in physics or engineering education, designed to teach dimensional analysis or approximation of extreme scientific calculatio ...
*
Mental calculation
Mental calculation (also known as mental computation) consists of arithmetical calculations made by the mind, within the brain, with no help from any supplies (such as pencil and paper) or devices such as a calculator. People may use menta ...
*
Proof of concept
A proof of concept (POC or PoC), also known as proof of principle, is an inchoate realization of a certain idea or method in order to demonstrate its feasibility or viability. A proof of concept is usually small and may or may not be complete ...
References
{{standard test item
Software testing
Error detection and correction