Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.RuntimeException
  2.  
  3. Activity activity = Robolectric.setupActivity(MainActivity.class);
  4.  
  5. buildscript {
  6. repositories {
  7. mavenCentral()
  8. jcenter()
  9. }
  10. dependencies {
  11. classpath 'com.android.tools.build:gradle:1.0.0'
  12. classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
  13.  
  14. // NOTE: Do not place your application dependencies here; they belong
  15. // in the individual module build.gradle files
  16. }
  17. }
  18.  
  19. allprojects {
  20. repositories {
  21. jcenter()
  22. }
  23. }
  24.  
  25. apply plugin: 'com.android.application'
  26.  
  27. repositories {
  28. mavenCentral()
  29. }
  30.  
  31. android {
  32. compileSdkVersion 21
  33. buildToolsVersion "21.1.2"
  34.  
  35. defaultConfig {
  36. applicationId "com.example.robolectrictest"
  37. minSdkVersion 15
  38. targetSdkVersion 21
  39. versionCode 1
  40. versionName "1.0"
  41. }
  42. buildTypes {
  43. release {
  44. minifyEnabled false
  45. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  46. }
  47. }
  48.  
  49. sourceSets {
  50. main {
  51. jniLibs.srcDirs = ['libs']
  52. }
  53.  
  54. androidTest {
  55. setRoot('src/androidTest')
  56. }
  57. }
  58. }
  59.  
  60. // Must be after Android plugin
  61. apply plugin: 'android-unit-test'
  62.  
  63. dependencies {
  64. compile fileTree(dir: 'libs', include: ['*.jar'])
  65. compile 'com.android.support:appcompat-v7:21.0.3'
  66.  
  67. //androidTestCompile 'junit:junit:4.10'
  68. //androidTestCompile 'org.robolectric:robolectric:2.4'
  69.  
  70. // Testing frameworks
  71. testCompile 'junit:junit:4.10'
  72. testCompile 'org.robolectric:robolectric:2.4'
  73. }
  74.  
  75. public class MainActivity extends ActionBarActivity {
  76.  
  77. @Override
  78. protected void onCreate(Bundle savedInstanceState) {
  79. super.onCreate(savedInstanceState);
  80. setContentView(R.layout.activity_main);
  81. }
  82.  
  83.  
  84. @Override
  85. public boolean onCreateOptionsMenu(Menu menu) {
  86. // Inflate the menu; this adds items to the action bar if it is present.
  87. getMenuInflater().inflate(R.menu.menu_main, menu);
  88. return true;
  89. }
  90.  
  91. @Override
  92. public boolean onOptionsItemSelected(MenuItem item) {
  93. // Handle action bar item clicks here. The action bar will
  94. // automatically handle clicks on the Home/Up button, so long
  95. // as you specify a parent activity in AndroidManifest.xml.
  96. int id = item.getItemId();
  97.  
  98. //noinspection SimplifiableIfStatement
  99. if (id == R.id.action_settings) {
  100. return true;
  101. }
  102.  
  103. return super.onOptionsItemSelected(item);
  104. }
  105. }
  106.  
  107. @Config(emulateSdk = 18)
  108. @RunWith(RobolectricTestRunner.class)
  109.  
  110. public class ApplicationTest {
  111.  
  112. @org.junit.Test
  113. public void testDummy() throws Exception {
  114.  
  115. Activity activity = Robolectric.setupActivity(MainActivity.class);
  116.  
  117. assertTrue(true);
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement