A unit test is code that is written and executed to test a specific portion/unit of source code. Tests that do not pass are considered failing. Tests that do not generate desired coverage are still considered to pass.

Questions related to the failure of unit tests when they are expected to pass should be tagged with the failing-tests tag.

Unit tests typically require setting up data on which the code under test operates. As of API version 24 (Spring '12) unit test methods do not have access to the organization's data by default, with the exception of setup and metadata objects. However, the organization's data can still be accessed by explicitly indicating that intent by using the @isTest(SeeAllData=true) annotation.

Once the data is set up the unit of code under test is executed and then typically System.assert assertions about the results of the execution are made.

To learn more about unit tests in Salesforce see the following.

history | excerpt history