トラッキング コード

4/29/2015

How to IntentsTestRule, in AndroidTest




About IntentsTestRule

IntentsTestRule is AndroidTest which can do intent test.

If use, we have to add Espresso-Intents library in build.gradle.
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.1'

Test Sample

The following code is sample which Intent has Intent.ACTION_CALL by user operation.
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityIntentTest {

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

    @Before
    public void stubAllExternalIntents() {
        // By default Espresso Intents does not stub any Intents. Stubbing needs to be setup before
        // every test run. In this case all external Intents will be blocked.
        intending(not(isInternal()))
                .respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null));
    }

    @Test
    public void callPhone() {
        // call action
        onView(withId(R.id.callButton)).perform(click());

        // test
        intended(allOf(
                hasAction(Intent.ACTION_CALL),
                hasData("tel:0123456789"),
                toPackage("com.android.server.telecom")));

    }
}
How to create test class.
  • create test class with RunWith annotation
  • add IntentsTestRule with Rule annotation

We can check whether Intent has occurred.
  • Intended method which check the intended Intent
  • matches method


  • Add Intent to Starting Activity

    If need to add Intent to Activity, we need to do override IntentsTestRule#getActivityIntent.
        @Rule
        public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class) {
    
            /**
            * add Intent to Activity
            */
            @Override
            protected Intent getActivityIntent() {
                Intent intent = new Intent();
                intent.putExtra(KEY_DATA,data);
                return intent;
            }
        };
    

    https://github.com/googlesamples/android-testing

    70 comments:

    1. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.

      rpa Training in Chennai

      rpa Training in bangalore

      rpa Training in pune

      blueprism Training in Chennai

      blueprism Training in bangalore

      blueprism Training in pune

      iot-training-in-chennai

      ReplyDelete
    2. I am a regular reader of your blog and being students it is great to read that your responsibilities have not prevented you from continuing your study and other activities. Love
      python training in rajajinagar
      Python training in btm

      ReplyDelete
    3. I always enjoy reading quality articles by an individual who is obviously knowledgeable on their chosen subject. Ill be watching this post with much interest. Keep up the great work, I will be back
      java training in omr | oracle training in chennai

      java training in annanagar | java training in chennai

      ReplyDelete
    4. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.

      Data Science Training in Chennai
      Data science training in bangalore
      Data science online training
      Data science training in pune

      ReplyDelete
    5. The site was so nice, I found out about a lot of great things. I like the way you make your blog posts. Keep up the good work and may you gain success in the long run.

      java online training | java course in pune

      java course in chennai | java course in bangalore

      ReplyDelete
    6. I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!
      Blueprism online training

      Blue Prism Training in Pune

      ReplyDelete
    7. This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb. This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolite festivity to pity. I appreciated what you ok extremely here.


      angularjs Training in chennai
      angularjs-Training in pune

      angularjs-Training in chennai

      angularjs Training in chennai

      angularjs-Training in tambaram

      ReplyDelete
    8. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

      AWS Interview Questions And Answers

      AWS Training in Bangalore | Amazon Web Services Training in Bangalore

      AWS Training in Pune | Best Amazon Web Services Training in Pune

      Amazon Web Services Training in Pune | Best AWS Training in Pune

      AWS Online Training | Online AWS Certification Course - Gangboard

      ReplyDelete
    9. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

      AWS Interview Questions And Answers

      AWS Training in Bangalore | Amazon Web Services Training in Bangalore

      AWS Training in Pune | Best Amazon Web Services Training in Pune

      Amazon Web Services Training in Pune | Best AWS Training in Pune

      AWS Online Training | Online AWS Certification Course - Gangboard

      ReplyDelete
    10. indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
      SOFTWARE TRAINING IN CHENNAI
      POWERBI TRAINING IN CHENNAI
      CCNA TRAINING IN CHENNAI
      ANDROID TRAINING IN CHENNAI

      ReplyDelete
    11. Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have.

      digital marketing course in chennai
      digital marketing training in chennai

      ReplyDelete
    12. This is my 1st visit to your web... But I'm so impressed with your content. Good Job!
      CCC Result 2020

      ReplyDelete
    13. Nice blog,I understood the topic very clearly,And want to study more like this.
      Swachata par Nibandh

      ReplyDelete

    14. Nice Article.very impressed for this informative
      ExcelR data analytics courses

      ReplyDelete
    15. Blogs are very Nice.The Information's provided in the Articles about Python are useful.keep updating and visit to know more about python
      python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

      ReplyDelete
    16. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.thanks a lot.
      Ai & Artificial Intelligence Course in Chennai
      PHP Training in Chennai
      Ethical Hacking Course in Chennai Blue Prism Training in Chennai
      UiPath Training in Chennai

      ReplyDelete
    17. Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

      Rowe Rowe
      Rowe Rowe
      Rowe Rowe
      Rowe Rowe
      Rowe Rowe

      Thank you..

      ReplyDelete
    18. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.

      data science interview questions

      ReplyDelete
    19. 45. You have put most of the high quality and valuable information here that any of the keen reader would adore to read. Great job!
      Data Science training in Mumbai
      Data Science course in Mumbai
      SAP training in Mumbai

      ReplyDelete

    20. Nice article and thanks for sharing with us. Its very informative




      AI Training in Hyderabad

      ReplyDelete


    21. Nice article and thanks for sharing with us. Its very informative

      Plots in TUKKUGUDA

      ReplyDelete
    22. we are here for you guys to enhance your skills during this period. Our institution offering you CS executive classes and free CSEET classes. So guys for more info contact us or visit us at website https://uniqueacademyforcommerce.com/

      ReplyDelete
    23. Don't Waste Your Time Checking CHF USD Every Day! Get The Most Accurate Exchange Rate For The CHF USD With Our Original Universal Currency Converter.

      ReplyDelete
    24. Want To Trade Forex With AVATRADE REVIEW ? Read This Blog First To Find Out About The Best Forex Trading Conditions. We Review The Most Popular Forex Brokers And Tell You What You Need To Know.

      ReplyDelete
    25. Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging,
      data science training in hyderabad

      ReplyDelete
    26. Do you want to avail the good and expertise services of a logistics company. There is one company in my mind, its name is AFM Logistics pvt Ltd .It gives best quality logistics service ,ie is AFM Logistics Pvt Ltd is an international freight forwarding and customs clearing company established in Delhi. The company was constituted in 2012 and is indulged in providing complete logistics solution. The company has its own setup and wide network of agents throughout the world. International Logistics Companies In India . They are the best air cargo and ocean freight forwarding company in Delhi, India. AFM Logistics Pvt Ltd has been working as Import and Export Agent in India since 2012. They have been providing personal baggage shipping services in India for a very long time.

      ReplyDelete
    27. Best AWS Training provided by Vepsun in Bangalore for the last 12 years. Our Trainer has more than 20+ Years
      of IT Experience in teaching Virtualization and Cloud topics.. we are very delighted to say that Vepsun is
      the Top AWS cloud training Provider in Bangalore. We provide the best atmosphere for our students to learn.
      Our Trainers have great experience and are highly skilled in IT Professionals. AWS is an evolving cloud
      computing platform provided by Amazon with a combination of IT services. It includes a mixture of
      infrastructure as service and packaged software as service offerings and also automation. We have trained
      more than 10000 students in AWS cloud and our trainer Sameer has been awarded as the best Citrix and Cloud
      trainer in india.

      ReplyDelete
    28. Great very helpful blog.
      jewellery shop management software
      Jewellery Shop Management Software

      ReplyDelete
    29. The IntentsTestRule in AndroidTest is a valuable tool for testing interactions with intents in Android applications. This article probably provides insights and guidance on how to effectively use this rule to write robust and reliable tests for Android apps.

      Data Analytics Courses In Kochi



      ReplyDelete
    30. The utilization of IntentsTestRule in Android testing, as exemplified here, is commendable for ensuring precise and reliable intent testing. An informative guide for Android developers!
      Data Analytics Courses In Dubai

      ReplyDelete
    31. Excellent tutorial on how to use AndroidTest's IntentsTestRule! It is simple to comprehend how to conduct intent testing successfully thanks to your explanation and code examples. I appreciate you sharing this.
      Data Analytics Courses in Agra

      ReplyDelete
    32. Thanks for this wonderful tutorial on the intent test rule in Andriod. Being an Android user it is so helpful for me.
      Visit - Data Analytics Courses in Delhi

      ReplyDelete
    33. Thanks for sharing informative and insightful tutorial on How to IntentsTestRule, in AndroidTest.
      data analyst courses in limerick

      ReplyDelete
    34. I’m really impressed by this blog! The variety of topics you cover keeps it fresh and interesting. I always look forward to your posts

      Data science courses in Gujarat

      ReplyDelete
    35. I really appreciate how informative and well-written this article is. The content is concise, actionable, and very relevant. I’m sure others will find it just as valuable. Thanks for taking the time to create this.
      Data Analytics Courses in Delhi

      ReplyDelete
    36. Your guide on using IntentsTestRule in AndroidTest is really helpful for improving test automation. It's clear and concise, making it easy to understand for developers aiming to enhance their testing skills. Keep up the great work!
      Data Science Courses in Singapore

      ReplyDelete
    37. We are glad to see this blog. It was helpful indeed and I appreciate your efforts for this article.
      Data science courses in Ghana

      ReplyDelete
    38. Great post! It offers a clear and concise introduction to using IntentsTestRule for intent testing in Android. The step-by-step guide, along with practical code samples, makes it easy to follow. I especially appreciate how you explained adding the Espresso-Intents library and the process of stubbing external intents for tests. The sample test with Intent.ACTION_CALL is super helpful for understanding how to test specific intents. Overall, a fantastic resource for anyone looking to get started with intent testing in Android.
      data analytics courses in dubai

      ReplyDelete
    39. Wat an amazing way to brief things you did an excellent job writing this. Very nice article.Thanks for sharing
      Data Science Courses in Hauz Khas

      ReplyDelete
    40. This is an insightful piece! I love how you tackled the complexities involved. It really gives readers a new perspective and encourages deeper thought on the subject. Keep up the great work!
      Online Data Science Course

      ReplyDelete
    41. Baroque Works Dev provides a clear and informative guide on using IntentTestRule in Android testing. The step-by-step instructions are easy to follow, making it a great resource for both novice and experienced developers. Highly recommend for anyone looking to enhance their Android testing skills

      data analytics courses in dubai

      ReplyDelete
    42. "This post about the Data Science Course in Dadar is fantastic!
      The course seems to cover all the essential skills needed in data science.
      I appreciate the emphasis on practical applications and projects.
      Having access to local training makes it so much easier to pursue my goals.
      I’ll definitely be looking into this course!"

      ReplyDelete
    43. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
      Data science Courses in Manchester

      ReplyDelete
    44. "I took IIM Skills’ Data science while living in Mumbai, and it has been fantastic. The online format fits seamlessly into my schedule."

      ReplyDelete
    45. Thank you for being such a source of motivation! Your positive outlook and determination are truly inspiring. I’m encouraged to push through my own obstacles!

      Data science courses in Mumbai

      ReplyDelete
    46. Great article! IntentsTestRule is incredibly helpful for testing intents in Android, and it's nice to see a practical example with Intent.ACTION_CALL. Data science courses in Mysore

      ReplyDelete
    47. Data science is undeniably one of the most in-demand fields, and it’s fantastic to see such an array of courses available in Iraq. Whether you're interested in data analysis, machine learning, or AI, these programs can help you build the skills necessary for success. Explore the best courses here and take the next step in your career!

      ReplyDelete
    48. this blog is very neat and clearly explained, thank for sharing.
      Data science course in Bangalore

      ReplyDelete
    49. This blog explains the implementation of IntentsTestRule for Android UI testing. A helpful tutorial for Android developers working on app testing and quality assurance!
      Data science course in Gurgaon

      ReplyDelete
    50. Interesting points, i want to read your other articles as well.
      Data science courses in chennai

      ReplyDelete
    51. I never realized how much I didn’t know until I read this. You’ve done a fantastic job of making complex topics simple and relatable
      Data science courses in Bangalore

      ReplyDelete
    52. Your explanation of how to IntentsTestRule, in AndroidTest was exactly what I needed. I feel more prepared to take action now. Thanks for the explanation. I finally understood the topic.
      Data Science Courses in China


      ReplyDelete
    53. Thanks for sharing these details. I found them very useful and informative.

      technical writing course

      ReplyDelete
    54. Thanks for the detailed explanation. This is really helpful for anyone looking for this.
      GST Course

      ReplyDelete
    55. The use of `IntentsTestRule` in Android testing simplifies the process of verifying that your app is sending the correct intents. By stubbing external intents and using the `intended()` method, you can test that the right action, data, and package are being triggered when interacting with the UI. This rule is essential for ensuring your app's behavior aligns with your expectations, especially when working with activities and external components. Investment Banking Course

      ReplyDelete