A sanity test or sanity check 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 may be checked to perform the test. The advantage of a sanity test, over performing a complete or rigorous test, is speed.
In arithmetic, for example, when multiplying by 9, using the divisibility rule 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, however it's a quick and simple method to discover many possible errors.
In computer science, a sanity test is a very brief run-through of the functionality of a computer program, 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.
- If one were to attempt to square 738 and calculated 53,874, a quick sanity check could show that this result cannot be true. Consider that 700 < 738, yet 700² = 7²×100² = 490,000 > 53,874. Since squaring positive integers preserves their inequality, the result cannot be true, and so the calculated result is incorrect. The correct answer, 738² = 544,644, is more than 10 times higher than 53,874, and so the result had been off by an order of magnitude.
- In multiplication, 918 × 155 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 8×5=40, but 142,135 does not end in "0" like "40", while the correct answer does: 918×155=142,290. An even quicker check is that the product of even and odd numbers is even, whereas 142,135 is odd.
- The power output of a car cannot be 700 kJ, since that is a measure of energy, not power (energy per unit time). This is a basic application of dimensional analysis.
||It has been suggested that this section be merged with Smoke testing (software). (Discuss) Proposed since December 2013.|
In software development, the sanity test (a form of software testing which offers "quick, broad, and shallow testing") determines whether it is possible and reasonable to proceed with further testing.
Software sanity tests are synonymous with smoke tests. A sanity or smoke test determines whether it is possible and reasonable to continue testing. It exercises the smallest subset of application functions needed to determine whether the systems are accessible and the application logic is responsive. If the sanity test fails, it is not reasonable to attempt more rigorous testing. Sanity tests are ways to avoid wasting time and effort by quickly determining whether an application is too flawed to merit any rigorous testing. Many companies run sanity tests on an automated build as part of their software development life cycle.
Sanity testing may be a tool used while manually debugging software. An overall piece of software likely involves multiple subsystems between the input and the output. When the overall system is not working as expected, a sanity test can be used to make the decision on what to test next. If one subsystem is not giving the expected result, the other subsystems can be eliminated from further investigation until the problem with this one is solved.
A "Hello, World!" program is often used as a sanity test for a development environment. If the program fails to compile or execute, the supporting environment likely has a configuration problem. If it works, any problem being diagnosed likely lies in the actual application in question.
Another, possibly more common usage of 'sanity test' is to denote checks which are performed within program 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 that a file opened, written to, or closed, did not fail on these activities – which is a sanity check often ignored by programmers. But more complex items can also be sanity-checked for various reasons.
Examples of this include bank account management systems which check that withdrawals are sane in not requesting more than the account contains, and that deposits or purchases are sane in fitting in with patterns established by historical data – large deposits may be more closely scrutinized for accuracy, large purchase transactions may be double-checked with a card holder for validity against fraud, ATM withdrawals in foreign locations never before visited by the card holder might be cleared up with him, etc.; these are "runtime" sanity checks, as opposed to the "development" sanity checks mentioned above.
- Proof of concept
- Back-of-the-envelope calculation
- Software testing
- Mental calculation
- Order of magnitude
- Fermi problem
- M. A. Fecko and C. M. Lott, ``Lessons learned from automating tests for an operations support system, Software--Practice and Experience, v. 32, October 2002.
- Erik van Veenendaal (ED), Standard glossary of terms used in Software Testing, International Software Testing Qualification Board.
- Hassan, A. E. and Zhang, K. 2006. Using Decision Trees to Predict the Certification Result of a Build. In Proceedings of the 21st IEEE/ACM international Conference on Automated Software Engineering (September 18 – 22, 2006). Automated Software Engineering. IEEE Computer Society, Washington, DC, 189–198.
- Darwin, Ian F. (January 1991). Checking C programs with lint (1st ed., with minor revisions. ed.). Newton, Mass.: O'Reilly & Associates. p. 19. ISBN 0-937175-30-7. Retrieved 7 October 2014.
A common programming habit is to ignore the return value from fprintf(stderr, ...