What is a sanity test/check

What is it and why is it used/useful?


A sanity test isn't limited in any way to the context of programming or software engineering. A sanity test is just a casual term to mean that you're testing/confirming/validating something that should follow very clear and simple logic. It's asking someone else to confirm that you are not insane and that what seems to make sense to you also makes sense to them... or did you down way too many energy drinks in the last 4 hours to maintain sanity?

If you're bashing your head on the wall completely at a loss as to why something very simple isn't working... you would ask someone to do a quick sanity test for you. Have them make sure you didn't overlook that semicolon at the end of your for loop the last 15 times you looked it over. Extremely simple example, really shouldn't happen, but sometimes you're too close to something to step back and see the whole. A different perspective sometimes helps to make sure you're not completely insane.


Good example is a sanity check for a database connection.

SELECT 1 FROM DUAL

It's a simple query to test the connection, see:

SELECT 1 from DUAL: MySQL

It doesn't test deep functionality, only that the connection is ok to proceed with.


The difference between smoke and sanity, at least as I understand it, is that smoke test is a quick test to see that after a build the application is good enough for testing. Then, you do a sanity test which would tell you if a particular functional area is good enough that it actually makes sense to proceed with tests on this area.

Example:

Smoke Test: I can launch the application and navigate through all the screens and application does not crash.

-If application crashes or I cannot access all screens, this build has something really wrong, there is "a fire" that needs to be extinguished ASAP and the vesion is not good for testing.

Sanity Test (For Users Management screen): I can get to Users Management screen, create a user and delete it.

  • So, the application passed the Smoke Test, and now I proceed to Sanity Tests for different areas. If I cannot rely on the application to create a user and to delete it, it is worthless to test more advanced functionalities like user expiration, logins, etc... However, if sanity test has passed, I can go on with the test of this area.

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 @ http://en.wikipedia.org/wiki/Sanity_testing