Android Robolectric unit testing JVM Core Dump when run all test together

854 views
Skip to first unread message

Armando Ferrero Camargo

unread,
Jan 10, 2014, 11:58:55 AM1/10/14
to robol...@googlegroups.com

Hi, at the moment I'm trying to test my android application using Robolectric 2.2. The app uses Android + Maven + RoboGuice + Volley etc.

The issue is the next one, i have some test which are working perfectly if i execute them individually through IDEA Intellij or using mvn . This tests are the unitary test of the different fragments contained into a main RoboFragmentActivity. My problem is that when I try to do “mvn clean install”, it start to run the tests, all together, and I get a JVM core dump like this:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f7c4481be84, pid=12755, tid=140168581252864
#
# JRE version: 7.0_09-b05
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.5-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C6,1,com.example.client.ForeignProfileTest,testForeignProfilePresentationNotNull(com.example.client.ForeignProfileTest),null,null,null
  [libpthread.so.0+0x9e84]  pthread_mutex_lock+0x4
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/armando/git/orpheus-client/android-client/hs_err_pid12755.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted (core dumped)

I can't understand why its not working all together because the tests work individually. Its not a memory leak, the app releases memory correctly.

I have heard that it could be related with Volley + Robolectric but I use Volley 1.0 and Robolectric 2.2, it suppose should work. Some posts that I saw too talks about the shadow objects that Robolectric do related with the callback generated by Volley. Im a little bit stuck with it.

Here is a example of test.

public class DiscoverFanTest extends CustomTestRunner {

    @Inject
    DiscoverFanView discoverFanView;

    private Concert concert;
    private List<Product> products;
    Artist artist;

    @Before
    public void setUp() {
        super.setUp();
        artist = new PrototypeAlbums().getArtists().get(0);
        discoverFanView.setArtist(artist);
        concert = orpheusService.getConcert();
        products = orpheusService.getProducts();

        startFragment(discoverFanView);
    }

    @After
    public void tearDown() {
        TestGuiceModule.tearDown();
        stopFragment(discoverFanView);
        discoverFanView= null;
        concert= null;
        products= null;
        artist= null;
    }

    @Test
    public void testDiscoverFanPresentationNotNull() {
        assert (new DiscoverFanPresentation(discoverFanView.getActivity().getApplicationContext(), discoverFanView) != null);
    }

    @Test
    public void testDiscoverFanImageConcert() {
        ImageView imageConcert = (ImageView) discoverFanView.getView()
                .findViewById(R.id.imageComponentConcertImageView);

        assert (imageConcert != null);
        assertFalse(imageConcert.isClickable());
        assert (imageConcert.getResources() != null);
        assertTrue(imageConcert.getBackground() instanceof Drawable);
    }
}

And this is the CustomTestRunner

@RunWith(RobolectricTestRunner.class)
public class CustomTestRunner {

    protected static NavigationView navigationView;
    protected IService Service = new MockService();
    protected static FragmentManager fragmentManager;

    public void setUp() {

        TestGuiceModule.setUp(this);
        navigationView = Robolectric.buildActivity(navigationView.class).create().start().resume().get();
        fragmentManager = navigationView.getSupportFragmentManager();
    }

    public void tearDown() {
        TestGuiceModule.tearDown();
    }

    public void startFragment(Fragment fragment) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction = fragmentTransaction.show(fragment);
        fragmentTransaction.add(fragment, null);
        fragmentTransaction.commit();
    }

    public void stopFragment(Fragment fragment) {
        if (fragment != null) {
            fragmentManager.beginTransaction().remove(fragment).commit();
            fragmentManager = null;
            orpheusNavigationView = null;
        }
    }

}

First of all thanks you, I hope someone could help me because i'm really obsess with it.

sae...@gmx.net

unread,
Jan 13, 2014, 8:42:49 AM1/13/14
to robol...@googlegroups.com
Hi,

I get the same error with Robolectric 2 and RoboGuice when I run all tests with Maven clean + install or inside Eclipse IDE:

OutOfMemoryError: PermGen space

Are there any known issues?

Erich Douglass

unread,
Jan 13, 2014, 11:37:53 AM1/13/14
to robol...@googlegroups.com
Robolectric rewrites classes at run time, which leads to a lot of PermGen allocations.  You will probably have to increase the Java heap size when running tests. If you use Maven, you can configure the test runner to use a larger heap:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.13</version>
        <configuration>
          <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=256m</argLine>
        </configuration>
      </plugin>


--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

sae...@gmx.net

unread,
Jan 15, 2014, 3:29:51 AM1/15/14
to robol...@googlegroups.com
Doesn´t really fix the problem. Also increasing MaxPermSize to 512m doesn´t work. I have 1400 robolectric tests. Nearly the first 1000 tests are running fine, but then I get the OOM PermGen.


Am Freitag, 10. Januar 2014 17:58:55 UTC+1 schrieb Armando Ferrero Camargo:

sae...@gmx.net

unread,
Jan 20, 2014, 6:15:47 AM1/20/14
to robol...@googlegroups.com
OK, was my issue, I set the PermSize at the wrong position. Now my tests run with PermSize of 512m.


Am Freitag, 10. Januar 2014 17:58:55 UTC+1 schrieb Armando Ferrero Camargo:
Reply all
Reply to author
Forward
0 new messages