Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.RuntimeException
- Activity activity = Robolectric.setupActivity(MainActivity.class);
- buildscript {
- repositories {
- mavenCentral()
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.0.0'
- classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
- allprojects {
- repositories {
- jcenter()
- }
- }
- apply plugin: 'com.android.application'
- repositories {
- mavenCentral()
- }
- android {
- compileSdkVersion 21
- buildToolsVersion "21.1.2"
- defaultConfig {
- applicationId "com.example.robolectrictest"
- minSdkVersion 15
- targetSdkVersion 21
- versionCode 1
- versionName "1.0"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- sourceSets {
- main {
- jniLibs.srcDirs = ['libs']
- }
- androidTest {
- setRoot('src/androidTest')
- }
- }
- }
- // Must be after Android plugin
- apply plugin: 'android-unit-test'
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:21.0.3'
- //androidTestCompile 'junit:junit:4.10'
- //androidTestCompile 'org.robolectric:robolectric:2.4'
- // Testing frameworks
- testCompile 'junit:junit:4.10'
- testCompile 'org.robolectric:robolectric:2.4'
- }
- public class MainActivity extends ActionBarActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- @Config(emulateSdk = 18)
- @RunWith(RobolectricTestRunner.class)
- public class ApplicationTest {
- @org.junit.Test
- public void testDummy() throws Exception {
- Activity activity = Robolectric.setupActivity(MainActivity.class);
- assertTrue(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement