Robolectric Eclipse setup; equalTo undefined

834 views
Skip to first unread message

Ferran Garriga Ollé

unread,
Sep 22, 2011, 5:59:36 AM9/22/11
to robol...@googlegroups.com
Hi to all,

I'm new using Robolectric and JUnit in general and I'm trying to test the basic example, but it seams that the method equalTo is undefined and it cannot be founded.

My Libraries:
- android.jar
- maps.jar
- robolectric.1.0-RC1-jar-with-dependencies.jar
- JRE System Library [JavaSE-1.6]
- JUnit 4

The source code of the test is:

package com.example;

import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.xtremelabs.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class UiMainTest {
@Test
public void shouldHaveHappySmiles() throws Exception {
String hello = new UiMain().getResources().getString(R.string.hello);
assertThat(hello, equalTo("Hello World, MyActivity!"));
}
}

The error that I get is

The method equalTo(String) is undefined for the type UiMainTest

Any idea?

Thanks.

c....@gmx.net

unread,
Sep 22, 2011, 8:07:31 AM9/22/11
to Robolectric
Yes,

add "import static org.junit.Assert.assertThat;"

Ferran Garriga Ollé

unread,
Sep 22, 2011, 8:10:31 AM9/22/11
to robol...@googlegroups.com
is already in the source code that I've pasted.

c....@gmx.net

unread,
Sep 22, 2011, 9:16:20 AM9/22/11
to Robolectric
Sorry, wrong import.

The right is:
import org.hamcrest.core.IsEqual.equalTo;
or
import org.hamcrest.core.IsEqual.*;
Message has been deleted

c....@gmx.net

unread,
Sep 22, 2011, 9:14:07 AM9/22/11
to Robolectric
Sorry wrong import.
import static org.hamcrest.core.IsEqual.equalTo;
or
import static org.hamcrest.core.IsEqual.*;

Chris Van Vranken

unread,
Sep 22, 2011, 8:47:44 AM9/22/11
to robol...@googlegroups.com

equalto comes from Hamcrest which is a junit dependency contained within the junit jar. You probably just need to import the static method for it from Hamcrest.

Ferran Garriga Ollé

unread,
Sep 22, 2011, 10:22:50 AM9/22/11
to robol...@googlegroups.com
Cool, it's working now, although I haven't seen that import in any example code...

A Chakra

unread,
Oct 10, 2014, 12:49:21 AM10/10/14
to robol...@googlegroups.com
Yeah perfect working for me

Roy Javier

unread,
Jan 25, 2015, 8:03:41 PM1/25/15
to robol...@googlegroups.com
hello,

i'm having trouble with my environment.
could you please tell me what are the versions of the setup that works for you?

eclipse -
android sdk -
android project min and target levels -
robolectric -
junit -
android.jar -
maps.jar -
jre/jdk -


thanks! :-)

Roy Javier

unread,
Jan 25, 2015, 8:09:14 PM1/25/15
to robol...@googlegroups.com
i'm using eclipse luna since adt is too heavy for my old PC.

could you please add the latest version numbers that works for you?


eclipse -
android sdk -
your android project min and target levels -
robolectric -
junit -
android.jar -
maps.jar -
jre/jdk -

also, do i have to use gradle or maven to configure/use robolectric?

thanks!

Csaba Kozák

unread,
Apr 16, 2015, 4:22:52 PM4/16/15
to robol...@googlegroups.com
If you are using m2e-android (Maven Android integration for Eclipse), it can configure your Robolectric tests out of the box, and
you can run them in the IDE.
Reply all
Reply to author
Forward
0 new messages