So I have this error, using Robolectric.
java.lang.IllegalArgumentException: Test class can only have one constructor
at org.junit.runners.model.TestClass.(TestClass.java:40)
at org.junit.runners.ParentRunner.(ParentRunner.java:75)
at org.junit.runners.BlockJUnit4ClassRunner.(BlockJUnit4ClassRunner.java:57)
at org.robolectric.RobolectricTestRunner$HelperTestRunner.(RobolectricTestRunner.java:626)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:198)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
To be honest, it worked weeks ago, but after few changes in my project it broke. I'm using 4.3_r1 platform version. Normal JUnit tests work well.
The test class:
@RunWith(RobolectricTestRunner.class)
public class PreferenceTest
{
@Before
public void setUp()
{
RoboGuice.setBaseApplicationInjector(Robolectric.application, RoboGuice.DEFAULT_STAGE,
Modules.override(RoboGuice.newDefaultRoboModule(Robolectric.application))
.with(new CoreConfigModule()));
}
@Test
public void testSessionTokenPrefs()
{
InternalPreferences.setSessionToken("abcd1234");
assertThat(InternalPreferences.getSessionToken()).isEqualTo("abcd1234");
InternalPreferences.clearSessionToken();
assertThat(InternalPreferences.getSessionToken()).isNull();
}
}