Problem with RE 3.0-rc2

183 views
Skip to first unread message

Ian Hunter

unread,
Jun 30, 2015, 3:38:42 PM6/30/15
to robol...@googlegroups.com
Hi Folks,

Really love RE, but having problems getting started.

I cant seem to get a really simple example of robolectric to work with AndroidStudio 1.2.2.

[ Maybe (from stack trace) its to do with running JUnit4IdeaTestRunner AND RobolectricTestRunner ????
  If so - how do I straighten this out?]

Any help really appreciated.
Many Thanks
Ian Hunter

====================================================
Error when i try to run test...

ava.lang.IllegalArgumentException: Test class can only have one constructor
at org.junit.runners.model.TestClass.<init>(TestClass.java:48)
at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.robolectric.RobolectricTestRunner$HelperTestRunner.<init>(RobolectricTestRunner.java:504)
at org.robolectric.RobolectricTestRunner.getHelperTestRunner(RobolectricTestRunner.java:277)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:207)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:185)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:149)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Process finished with exit code 255

====================================================

I have no idea where to start with this. Search yielded nothing I could apply.

Some src. below. I can supply more if necessary

====================================================
Test...

package android.xxxx.com.roboguicetestproject;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import static org.junit.Assert.*;

/**
* Created by ianhunter on 30/06/2015.
*/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, emulateSdk = 21)
public class MainActivityTest {

@Test
public void testOnRandomButtonClicked() throws Exception {

}
}
====================================================


====================================================
Gradle file...

apply plugin: 'com.android.application'
apply plugin: 'org.robolectric'

android {

compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "android.xxxx.com.roboguicetestproject"
minSdkVersion 6
targetSdkVersion 22
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'org.robolectric:robolectric:3.0-rc2'
testCompile 'junit:junit:4.+'
}

Ian Hunter

unread,
Jun 30, 2015, 5:10:39 PM6/30/15
to robol...@googlegroups.com
Follow up....

So it seems to be...

@RunWith(RobolectricTestRunner.class) // Gives me the error


@RunWith(JUnit4.class) // This works fine

Ian

Kanishk Tripathi

unread,
Jul 1, 2015, 6:29:00 PM7/1/15
to robol...@googlegroups.com
Have you tried to run it without the robolectric plugin?
I am using Android studio 1.2.1.1 and I am not using apply plugin: 'org.robolectric'
There was problem in running robolectric tests on previous versions of android studio and running with gradle. There were several solutions and fixes but those issues are not relevant now with new Android studio versions.
@RunWith(Junit.class) will run but will not be able to execute anything in android.jar

Ian Hunter

unread,
Jul 2, 2015, 3:58:25 AM7/2/15
to robol...@googlegroups.com
Thanks Kanishk. I'll give that a try tonight.

IH

--
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/d/optout.

Muranga James

unread,
Aug 4, 2015, 12:31:34 PM8/4/15
to Robolectric
Hello Ian, 

I am having the same issue did you find a solution to this ?

Ian Hunter

unread,
Aug 6, 2015, 5:47:55 PM8/6/15
to robol...@googlegroups.com
HI Muranga,

No I didnt solve it as such. Since I was in the early stages, I simply got a copy of the demo project, got that to work, and then transferred my source code in to that. Everything was fine from there on :-)

HTH
IanHunter

Brian Gardner

unread,
Oct 20, 2015, 3:34:56 PM10/20/15
to Robolectric
Hey Ian,

The issue you are having is caused by your package name. Your package is 'android.xxxx.com.testproject' and this is causing the issues. I'm not sure of the exact reason but I think the test runner assumes your test component is part of the android os since 'android' is the first part of your package name. If you switch your package name around to 'com.xxxx.android.testproject' then you should not run into this issue. Hope this help!

Brian Gardner
Reply all
Reply to author
Forward
0 new messages