Skipping code during unit tests - El Toro - Find articles about Visualforce, Apex, and Salesforce in general

Print Preview

Skipping code during unit tests

As demonstrated on the following code, the Test.isRunningTest() instructions allows you to specify some code that will only run (or not run) on test mode.

This is the Apex code:

public class aaPage75 {
    public PageReference SampleMethod() {
        System.debug('In Code');
        if (!Test.isRunningTest()) {
            System.debug('This should be shown only in regular execution');
        System.debug('In Code');
        return null;
    private static TestMethod void myTestMethod() {
        aaPage75 ts = new aaPage75();

comments powered by Disqus

© El Toro . IT @ 2013
Andrés Pérez