I'm developing an Android application using Android Studio, multidex feature and with the support library to use FragmentActivity
and Fragment
.
I've set up unit tests with the following Gradle configuration:
android {
// ...
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
// ...
dependencies {
// ...
androidTestCompile('com.android.support.test:runner:0.3')
// ...
}
Considering the following Activity
:
public class MainActivity extends android.support.v4.app.FragmentActivity {
When I wrote a test class to test it with Robotium, I declared it like:
public class TestRobotiumMainActivity extends ActivityInstrumentationTestCase2<MainActivity> {
public TestRobotiumMainActivity() {
super(MainActivity.class);
}
When running tests, I came up with the following error:
java.lang.NoClassDefFoundError: com.myapplication.app.activities.MainActivity
To better understand the point, I wrote the following test:
import static org.assertj.core.api.Assertions.assertThat;
public class TestMock extends AndroidTestCase {
//region Test methods
public void testMethod() {
assertThat(android.app.Activity.class).isNotNull();
assertThat(android.support.v4.app.FragmentActivity.class).isNotNull();
assertThat(com.myapplication.app.activities.MainActivity.class).isNotNull();
}
//endregion
}
And the test fails on the last line, giving the same error as above.
And when I change my MainActivity
to extend android.app.Activity
, the test turns to success.
Could someone suggest me a solution to solve this issue please?
Aucun commentaire:
Enregistrer un commentaire