There is a test method:

@Test public void scrollToItemBelowFold_checkItsText() { // First scroll to the position that needs to be matched and click on it. onView(ViewMatchers.withId(R.id.recyclerView)) .perform(RecyclerViewActions.actionOnItemAtPosition(ITEM_BELOW_THE_FOLD, click())); // Match the text in an item below the fold and check that it's displayed. String itemElementText = mActivityRule.getActivity().getResources().getString( R.string.item_element_text) + String.valueOf(ITEM_BELOW_THE_FOLD); onView(withText(itemElementText)).check(matches(isDisplayed())); } 

In which is present

 Test class showcasing some {@link RecyclerViewActions} from Espresso 

I try to cut it in gradle in different ways:

 androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' androidTestCompile 'com.android.support:support-annotations:25.0.1' 

`but alas, it fails, gives errors

androidTestCompile 'com.android.support.test.espresso: espresso-core: 2.2.2' androidTestCompile 'com.android.support.test: runner: 0.5' androidTestCompile 'com.android.support.test.espresso: espresso-contrib: 2.2.2 'androidTestCompile' com.android.support:support-annotations:25.0.1 'androidTestCompile' com.android.support.test.espresso: espresso-core: 2.2.2 'androidTestCompile' com.android.support.test: runner: 0.5 'androidTestCompile' com.android.support.test.espresso: espresso-contrib: 2.2.2 'androidTestCompile' com.android.support:support-annotations:25.0.1 'androidTestCompile' com.android.support.test. espresso: espresso-core: 2.2.2 'androidTestCompile' com.android.support.test: runner: 0.5 'androidTestCompile' com.android.support.test.espresso: espresso-contrib: 2.2.2 'androidTestCompile' com.android. support: support-annotations: 25.0.1 'androidTestCompile' com.android.support.test.espresso: espresso-core: 2.2.2 'androidTestCompile' com.android.support.test: runner: 0.5 'androidTestCompile' com.android. su pport.test.espresso: espresso-contrib: 2.2.2 'androidTestCompile' com.android.support:support-annotations:25.0.1 'androidTestCompile' com.android.support.test.espresso: espresso-core: 2.2.2 ' androidTestCompile 'com.android.support.test: runner: 0.5' androidTestCompile 'com.android.support.test.espresso: espresso-contrib: 2.2.2' androidTestCompile 'com.android.support:support-annotations:25.0.1'

Tell me, how can I fix it? And then similar decisions by.

  • What errors does it give? - Mikhail Vaysman

2 answers 2

Well, with such an approach, you can turn from a programmer into a mangalich, a barbeque) as you please) If you leave everything halfway down each time, you will not go far, but now to the question:

When you create a new project, you immediately create Espesso support in your build.gradle, which looks like this:

  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) 

As you have noticed, he complements the following groups. Further, to work, you will need some of the compiles, which I propose to add along with the following additions approximately as follows:

 androidTestCompile ('com.android.support.test:runner:0.5', { exclude group: 'com.android.support', module: 'support-annotations' }) androidTestCompile ('com.android.support.test:rules:0.5', { exclude group: 'com.android.support', module: 'support-annotations' }) 

Of course, you can also register without exclude, but most likely this is where your problem lies.

Also, if you are going to test intents / webview, you can add:

 // add this for intent mocking support androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2' // add this for webview testing support androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2' 

Well, the last note, see that your versions coincide everywhere. For clarity:

 compileSdkVersion 24 buildToolsVersion "24.0.2" ... compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.android.support:recyclerview-v7:24.2.1' compile 'com.android.support:cardview-v7:24.2.1' androidTestCompile 'com.android.support:support-annotations:24.2.1' 

Also, if you are testing Recycler, you can add the following:

 //RecyclerView androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') { exclude group: 'com.android.support', module: 'appcompat' exclude group: 'com.android.support', module: 'support-v4' exclude module: 'recyclerview-v7' } 

To sum up, you can try other tools, such as calabash for example. Try it, and everything will work out)

  • Many thanks, helped! - Inkognito
  • The meaning of the answer was that the main emphasis should be placed on the development, not on debugging the testing of the tester :) Or God forbid, to debug the testing of the tester. - Barmaley
  • @Barmaley Well, as far as I know, writing tests is a good practice, and only then the development itself. - Morozov
  • @Morozov this practice was invented by worthless project managers who are so trying to control the developers. If you start working in the industry, you will understand that writing tests is evil for a developer and a boon to a project manager or team leader - Barmaley
  • @Barmaley, I still do not agree with you) because if during the course of your development something breaks in you, then the search for the problem takes much more time. And yes, it simplifies the work of other industries, but this is not bad) the same cucumber that reduces your explanations at times. - Morozov

I am in such cases stupidly throwing out the instrument. I will explain my concept, namely:

learning to own a tool should not be more expensive than learning the basic craft itself

Well, that is, they bring me a brand new brilliant tool, namely The Espresso testing framework , I gladly put it on and try to use it. Well, of course, from the first time the tool does not work, we read the manual - another attempt, it also does not start. 2-3 more iterations and that's it - I throw out the tool.

Let me remind you that Espresso is a tool for testing, and not for development, it is not new, not a new pattern, not a new framework - but just a testing tool. That is, it does not create new functionality, it does not create a new UI, it does not create anything. It is just a tool for testing.

Well, the type you have a cool new brazier on which you are famously able to fry kebabs. A peasant rolls up to you and says: “Hey, I have a super-duper thermometer for meat, with the help of which you will make kebabs even better - please try. And you try, and you find that you can’t turn on this tricky thermometer - there are a lot of buttons there. Your actions are correct, you will throw out a thermometer, for a crowd of people are waiting for kebabs and banging forks on plates and yelling: “Serve kebabs!”.

Summary: throw the hell out of this Espresso and enjoy barbecue :)

Happy New Year!