2015-01-18 3 views
2

Я копаю более недели для тестов на андроид с эспрессо. Я не могу заставить Idle resourses работать правильно в моем проекте (интегрироваться в проект). Вот что я добавил build.gradle:Android Espresso не работает должным образом

dependencies { 
    // Testing-only dependencies 
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' 
} 

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

Что находится в тестовом классе:

SetUp: 
countingResource = new CountingIdlingResource("HelloWorldServerCalls"); 
Espresso.registerIdlingResources(countingResource);  

В Метод испытания:

Espresso.onView(ViewMatchers.withId(R.id.btnLogIn)).check(ViewAssertions.matches(ViewMatchers.isDisplayed())); 
     Log.d(TAG, "We are in WalkthroughActivity, user is not logged in"); 

//press button - walk to next activity 
Espresso.onView(ViewMatchers.withId(R.id.btnLogIn)).perform(ViewActions.click()); 

//register MyUserHelperV2 - this is Server decorator 
final LoginActivity act = (LoginActivity) getCurrentActivity(); 
     LoginActivity.Server aHelper = act.getUserHelper(); 
     MyUserHelperV2 helper = new MyUserHelperV2(aHelper, countingResource); 
     act.setUserHelper(helper); 

    //set password and email 
    Espresso.onView(ViewMatchers.withId(R.id.email)).perform(ViewActions.typeText("[email protected]")); 
    Espresso.onView(ViewMatchers.withId(R.id.password)).perform(ViewActions.typeText("password111")); 
     //Check if button R.id.btnLogInApp exists: 
Espresso.onView(ViewMatchers.withId(R.id.btnLogInApp)).check(ViewAssertions.matches(ViewMatchers.isDisplayed())); 

Espresso.closeSoftKeyboard(); 
    Espresso.onView(ViewMatchers.withId(R.id.btnLogInApp)).perform(ViewActions.click()); 
    //in last line we have PerformException - can not find R.id.btnLogInApp, 

Но наверняка эта кнопка существует - я может эмулировать не-простоя (синхронный) вызов, и все работает нормально. Я думаю, что могу совершить ошибку в настройках - на андроиде 5 все работает, на других андроидах < 5 - нет.

Я прорыл много образцов, и, безусловно, реализовал Idle res отлично. Но я слишком плохой с системой градиентов. Пожалуйста, помогите, я в отчаянии с эспрессо и градицией, я могу при необходимости добавить дополнительный код спецификации.

+1

не могли бы вы сообщить, какую ошибку вы получаете? – testsingh

ответ

0

Вот build.gradle пример файла

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 22 
    buildToolsVersion "22" 

defaultConfig { 
    applicationId "com.my.awesome.app" 
    minSdkVersion 10 
    targetSdkVersion 22.0.1 
    versionCode 1 
    versionName "1.0" 

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
} 

dependencies { 
// App's dependencies, including test 
compile 'com.android.support:support-annotations:22.2.0' 

// Testing-only dependencies 
androidTestCompile 'com.android.support.test:runner:0.5' 
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 
} 

И класс тест Exemple

Android Studio создать тест по умолчанию в ИПВ/androidTest/Java/com.example.package/

@RunWith(AndroidJUnit4.class) 
@LargeTest 
public class HelloWorldEspressoTest { 

@Rule 
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); 

@Test 
public void listGoesOverTheFold() { 
    onView(withText("Hello world!")).check(matches(isDisplayed())); 
} 
} 
Смежные вопросы