Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.concurrent.atomic.AtomicBoolean; public class Main { private static AtomicBoolean isRunningTest; private static synchronized boolean isRunningTest() { if (null == isRunningTest) { boolean isTest; try { Class.forName("android.support.test.espresso.Espresso"); isTest = true; } catch (ClassNotFoundException e) { isTest = false; } isRunningTest = new AtomicBoolean(isTest); } return isRunningTest.get(); } }