title: Robolectric Unit Testing Sugar ORM
body: <p>I'm new with unit testing, even newer with Robolectric.
  Now, I'm trying to run Robolectric testing with Sugar ORM, but keep getting this message </p>
  
  <pre><code>objc[535]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
  Connected to the target VM, address: '127.0.0.1:61500', transport: 'socket'
  No such manifest file: /Users/virginia/Documents/Android%20Developer/ravnandroid_v5/app/build/intermediates/manifests/full/debug/AndroidManifest.xml
  meta data -&gt; {}
  java.lang.NullPointerException: SugarContext has not been initialized properly. Call SugarContext.init(Context) in your Application.onCreate() method and SugarContext.terminate() in your Application.onTerminate() method.
  
      at com.orm.SugarContext.getSugarContext(SugarContext.java:24)
      at com.orm.SugarRecord.save(SugarRecord.java:360)
      at com.orm.TestSugarApp.insertUserTest(TestSugarApp.java:53)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [...]
  
  Disconnected from the target VM, address: '127.0.0.1:61500', transport: 'socket'
  
  Process finished with exit code 255
  </code></pre>
  
  <p>This is my <strong>graddle</strong> dependency:</p>
  
  <pre><code>compile group: 'com.google.guava', name: 'guava', version: '19.0'
  testCompile 'junit:junit:4.12'
  testCompile "org.robolectric:robolectric:3.1.2"
  </code></pre>
  
  <p>Test Class</p>
  
  <pre><code>package com.orm;
  
  @RunWith(CustomRoboelectricGradleTestRunner.class)
  @Config( constants = BuildConfig.class, sdk = 23)
  public class TestSugarApp {
  
      @Test
      public void startEverTestSugarAppAsFirst() {
          assertEquals(4, 2 + 2);
      }
  
      @Test
      public void insertUserTest() {
          DBRavnUser user = new DBRavnUser("8099999999", "Sample User");
          long id = user.save();
          assertEquals(id &gt; 0, id);
      }
  }
  </code></pre>
  
  <p>This, my RobolectricGradleTestRunner extension:</p>
  
  <pre><code>public class CustomRoboelectricGradleTestRunner extends RobolectricGradleTestRunner {
      public CustomRoboelectricGradleTestRunner(Class&lt;?&gt; testClass) throws InitializationError {
          super(testClass);
          String buildVariant = (BuildConfig.FLAVOR.isEmpty()
                  ? "" : BuildConfig.FLAVOR+ "/") + BuildConfig.BUILD_TYPE;
          String intermediatesPath = BuildConfig.class.getResource("")
                  .toString().replace("file:", "");
          intermediatesPath = intermediatesPath.substring(0, intermediatesPath.indexOf("/classes"));
  
          System.setProperty("android.package",
                  BuildConfig.APPLICATION_ID);
          System.setProperty("android.manifest",
                  intermediatesPath + "/manifests/full/" + buildVariant + "/AndroidManifest.xml");
          System.setProperty("android.resources", intermediatesPath + "/res/merged/" + buildVariant);
          System.setProperty("android.assets", intermediatesPath + "/assets/" + buildVariant);
      }
  
      @Override
      protected AndroidManifest getAppManifest(Config config) {
  
          String manifestProperty = System.getProperty("android.manifest");
          String resProperty = System.getProperty("android.resources");
          String assetsProperty = System.getProperty("android.assets");
          AndroidManifest manifest = new AndroidManifest(
                  Fs.fileFromPath(manifestProperty),
                  Fs.fileFromPath(resProperty),
                  Fs.fileFromPath(assetsProperty)) {
  
              @Override
              public Map&lt;String, Object&gt; getApplicationMetaData() {
                  Map&lt;String, Object&gt; metadata =  super.getApplicationMetaData();
                  metadata.put("DATABASE", "rcn.db");
                  metadata.put("VERSION", "16");
                  metadata.put("QUERY_LOG", "false");
                  metadata.put("DOMAIN_PACKAGE_NAME", BuildConfig.APPLICATION_ID);
                  return metadata;
              }
          };
          manifest.setPackageName(BuildConfig.APPLICATION_ID);
          return manifest;
      }
  }
  </code></pre>
  
  <p>As you see here, I'm overriding <code>getApplicationMetaData</code> to setup SugarORM metadata info.</p>
  
  <p>Any help in the correct direction will be appreciated.</p>
  
  <p>Regards.</p>