title: How can I tell if my Android app is being run by the InstrumentationTestRunner?
body: <p>In my app (a gradle-based, Android Studio project), I have a need to create a file with a different name when running under test. For instance, in production I would like to use the name <em>com.myapp.file</em> and when running under test, <em>com.myapp.file.<strong>tests</em></strong>.</p>
  
  <p>What I wanted to do was do this:</p>
  
  <p><code>String packageName = getApplicationContext().getPackageName();
  MyFile file = new MyFile(packageName);</code></p>
  
  <p>I was hoping that the <em>packageName</em> would automatically be different when running under test  (./gradlew connectedInstrumentTest) vs. normally. I checked my manifest and it shows that my test manifest has a package name ending with <strong>.test</strong>, but it doesn't seem to be passing this through to the app when running.</p>
  
  <p>Is there a way to either:</p>
  
  <p>1) Update my gradle or project files to use a different package name when running tests</p>
  
  <p>-or-</p>
  
  <p>2) Is there a way to programatically tell than my app is running under test?</p>