Friday, April 5, 2013

The Test Lifecycle in 2.0

Starting with Robolectric 2.0 alpha 3, there are some changes in how Robolectric prepares to run your tests.

Finding Your Application

By default, Robolectric first looks in your AndroidManifest.xml for the class to load as your application:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myapp">
  <application android:name=".Application"/>
</manifest>

That will cause a class called com.myapp.Application to be loaded. However, if you create a class with the same name and package, but with "Test" prepended to the class name, Robolectric will load that instead.

package com.myapp;
class TestApplication extends Application {
}

The Application Lifecycle

Robolectric now automatically calls an application's onCreate() method before the test runs, and onTerminate() after the test runs. Note that this a change from earlier versions. If you want to prevent your application's onCreate() method from being called, you can override it in a test class and have it do nothing.

If your test application implements the TestLifecycleApplication interface, it will get called with a few more useful events:

class TestApplication extends Application
    implements TestLifecycleApplication {
  @Override public void beforeTest(Method method) {
  }

  @Override public void prepareTest(Object test) {
  }

  @Override public void afterTest(Method method) {
  }
}

The overall steps taken when running each test, then, are:
  1. Create your application.
  2. Call application.onCreate().
  3. Call application.beforeTest().
  4. Call application.prepareTest().
  5. Run the test.
  6. Call application.onTerminate().
  7. Call application.afterTest().

These changes should make it possible for many people to avoid overriding RobolectricTestRunner altogether. Note that you can still change this by using your own subclass of RobolectricTestRunner, which provides a different TestLifecycle class.

456 comments:

  1. Sweet!

    But any plans to allow simpler tests to avoid dealing with application bootstrap altogether? If all you need is to mock a few of Android's final classes that's a lot of overhead.

    ReplyDelete
    Replies
    1. Yep, good point. We could make it switchable, something like @Config(createApplication = false).

      Regarding test startup time, the biggest cost by far now is reading in all the resource files. I think we'll get a huge win by lazily loading stuff where we can, which is close on the list.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Any progress on either issue here?
      MikiNW

      Delete
  2. A few questions:

    1. Where to find Robolectric 2.0 alpha 3? It doesn't appear to be on maven.
    2. We're working on a relatively new project, is 2.0 alpha 3 stable enough for us to use, or will we constantly be running into weird issues that will be resolved prior to release?
    3. Is 2.0 compatible with junit 4.11? I assume it is but thought I'd ask (while I'm at it).

    ReplyDelete
  3. I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

    ReplyDelete
  4. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin.Keep update more blog.
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

    ReplyDelete

  5. "That’s a huge collection of your blog. Really it’s amazing"!!
    "this is superb.. thank you.."!!
    iphone app developer

    ReplyDelete
  6. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    Mobile App Development Company
    Mobile App Development Companies

    ReplyDelete
  7. I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
    Android App Development Company

    ReplyDelete
  8. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Mobile App Development Company

    ReplyDelete
  9. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    Web Design Development Company
    Web design Company in Chennai
    Web development Company in Chennai

    ReplyDelete
  10. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Fitness SMS
    Salon SMS
    Investor Relation SMS

    ReplyDelete
  11. it is really amazing...thanks for sharing....provide more useful information...
    Mobile app development company

    ReplyDelete
  12. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    iOS App Development Company

    ReplyDelete
  13. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

    ReplyDelete
  14. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    snapho

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Hi,

    Thanks for sharing a very interesting article about The Test Lifecycle in 2.0. This is very useful information for online blog review readers. Keep it up such a nice posting like this.

    From,
    Maestro Infotech,
    Web Design Company Bangalore

    ReplyDelete
  17. thank you for sharing an excellent post.

    https://www.creatorswebindia.com/

    Web Design in chennai

    Web design Company in chennai

    Website Design in chennai

    Website Design Company in chennai

    website company in chennai

    Web development in chennai

    Web development Company in chennai

    Web Designer in chennai

    Web Designer Company in chennai

    website designer in chennai

    website designer company in chennai

    ReplyDelete
  18. Hey Thanks for sharing this valuable information with us. I will come back to your site and keep sharing this information with us. Also, don't forget to read the latest taco bell customer satisfaction survey here.tellthebell
    Hey Thanks for sharing this valuable information with us. I will come back to your site and keep sharing this information with us. Also, don't forget to read the latest taco bell customer satisfaction survey here.tellthebell

    ReplyDelete
  19. Hey Blogger, you have written a masterpiece with lots of information and I must say that you should post daily. Visit Us too kroger feedback

    ReplyDelete
  20. http://pixselo.com/our-services/web-development-company/

    Pixselo Global Solutions - Digital | Technology | Media

    ReplyDelete
  21. Thanks for sharing informative article. Asperina Technosoft is leading web development company offering professional service to customers across the globe at affordable price. Follow us at Facebook.

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. First this is a really Creative and Unique Article. Well, the main reason of me sharing my post here is that, We being the Digital Marketing Company In India are open for Partnerships with Mobile App Development, Website Development and Graphics related company !

    Get in touch with the Digital Marketing Services In India for more information

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. I think this is the best article today about the future technology. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Artificial Intelligence Training in Bangalore. Keep sharing your information regularly for my future reference.

    ReplyDelete
  27. I think this is the best article today about the future technology. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Artificial Intelligence Training in Bangalore. Keep sharing your information regularly for my future reference.

    ReplyDelete
  28. Excellent post. I learned a lot from this blog and I suggest my friends to visit your blog to learn new concept about technology.
    Data Science Course in Chennai
    Data Science Training in Chennai
    Data Analytics Courses in Chennai
    Big Data Analytics Courses in Chennai

    ReplyDelete
  29. First this is a really Creative and Unique Article. Well, the main reason of me sharing my post here is that, We have written a detailed post on the which can be used by Content Marketing Companies. Do check it out and let us know.

    Top Digital Marketing Companies in India

    List of Best Digital Marketing Companies in Bangalore

    Content Writing Samples

    ReplyDelete
  30. Looking to add extra style to your content, make use of our strikethrough Text Generator to add amazing line through text in desired platform. Strikethrough in Google Docs.

    ReplyDelete
  31. Very informative article..Thanks for sharing the best info for android Application...

    ReplyDelete
  32. EPSXE APK:- EPSXE is a Playstation emulator which is available for Android users. This EPSXE was a very popular port for pc. EPSXE has many superlative


    ePSXe for Android

    ReplyDelete
  33. https://www.veilleuse.shop/produit/veilleuse-coranique-munawara/
    La veilleuse coranique bluetooth avec sa télécommande pour offrir.
    Cadeau ramadam idéal
    La veilleuse coranique personnalisée pas cher
    Veilleuse coranique personnalisée
    Veilleuse coranique personnalisée

    Découvrez La veilleuse coranique Munawara
    Video de la Veilleuse coranique munawara
    Veilleuse coranique munawara


    Je travailles sur un projet de fabrication de cornes de gazelle personnalisée
    cornes de gazelle expressives
    cornes de gazelle délicieuses
    Merci de laisser ce lien c'est sympa...

    Le casque vapeur hair steamer permet de lutter contre la sécheresse, la chute des cheveux et leur mauvaise santé , dans le confort de votre domicile. Le hair steamer est un casque vapeur qui apporte une dose d'hydratation pour les cheveux crépus.
    Hair steamer vapohair
    Lee hair steamer casque vapeur est recommendé par fes femmes aux cheveux crépus
    Casque vapeur
    La casque vapeur hair steamer apporte beaucoup de bienfait au cheveux crépus de type afro Hair.
    hair steamer Casque vapeur hydratation cheveux crépus
    hair steamer
    Le hair steamer casque vapeur fournit une cure intense contre les chutes et pour favoriser la repousse.
    Le hair steamer est un casque à vapeur sûr, une utilisation et un entretien facile

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. Hi! Thanks for sharing this very interesting article Check out our latest TacobellSurvey.

    ReplyDelete
  36. The post is really good, we will use above mentioned strategy in our SEO services in Bangalore.

    ReplyDelete
  37. You can write a song about anything, but that sometimes makes it harder to get started than anything else. Some people use experiences from their personal life as inspiration, and others write things that they have read about. No matter what you choose to write on, anyone can write their own easy way to write a song lyrics with a bit of practice.

    ReplyDelete
  38. This is really a very good blog post and thanks for sharing it with the community!
    professional web design company in chennai
    web design company in chennai

    ReplyDelete
  39. This is really a very good blog post and thanks for sharing it with the community!
    professional web design company in chennai
    web design company in chennai

    ReplyDelete
  40. Thanks Infonya, admin.

    Untuk mencari referensi website pertanian, peternakan dan perikanan saya sarankan untuk mengunjungi website ini ya min.Soalnnya sangat lengkap dan mudah dipahami.


    Ilmu Pengetahuan

    Ilmu Peternakan

    ReplyDelete
  41. This comment has been removed by the author.

    ReplyDelete
  42. Awesome post, Great Landing here, Keep going, have a great Success!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    we are providing Elearning Company in Chennai since
    Digital Learning Solutions is a big boom to the Students and employee Engagement
    Mycoach Learning is the best certified Elearning Company, which offers
    Mycoach LMS

    ReplyDelete
  43. Вече имате много интересна статия. Благодарение на споделения администратор

    bán chó bull pháp tại hà nội

    giống chó bull pháp

    chó bull pháp đen

    mua chó bull pháp ở đâu

    ReplyDelete
  44. This comment has been removed by the author.

    ReplyDelete
  45. Bài viết bạn rất hay:



    Chúng tôi là đơn vị cung cấp các sản phẩm chất lượng như:



    Giảo cổ lam



    giảo cổ lam giải độc gan



    giảo cổ lam giảm béo

    ReplyDelete
  46. Bài viết bạn rất hay:



    Chúng tôi là đơn vị cung cấp các sản phẩm chất lượng như:



    lều xông hơi



    lều xông hơi sau sinh



    lều xông hơi giá bao nhiêu


    ReplyDelete
  47. Nice information keep sharing with us. Please check out web developer also. I hope it will help you.

    ReplyDelete
  48. Awesome post, Great to Land here, Keep going, have a great Success!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    we are providing Elearning Company in Chennai since
    Digital Learning Solutions is a big boom to the Students and employee Engagement
    Mycoach Learning is the best certified Elearning Company, which offers
    Mycoach LMS

    ReplyDelete
  49. Il tempo è gratis ( bán đá Sapphire thô ) non ha prezzo. Non puoi possederlo,( vòng đá ruby đỏ ) ma puoi usarlo. Puoi usarlo, ma non puoi tenerlo.( đá spinel ) Una volta perso, non sarai( đá ruby đỏ lục yên ) in grado di recuperarlo.

    ReplyDelete
  50. Vanskeligheter( van bi ) vil passere. På samme måte som( van điện từ ) regnet utenfor( van an toàn ) vinduet, hvor nostalgisk( van bướm ) er det som til slutt vil fjerne himmelen.

    ReplyDelete
  51. Thanks for sharing helpful information ,I had learned more things on this blog
    web design company in chennai

    ReplyDelete
  52. Метавонед, ки як мақолаи бузургу аъло ба монанди ин ба шумо муроҷиат кунед. Табрикот!

    giảo cổ lam giảm cân

    giảo cổ lam giảm béo

    giảo cổ lam giá bao nhiêu

    giảo cổ lam ở đâu tốt nhất

    ReplyDelete
  53. This is really a very good blog post and thanks for sharing it with the community!
    web design company in chennai

    ReplyDelete
  54. Si el agua cae al lago, desaparecerá( phụ kiện tủ bếp ). Pero si cae a la hoja de( phụ kiện tủ áo ) loto, brillará como una joya. Caer igual pero( thùng gạo thông minh ) estar con alguien es importante.

    ReplyDelete
  55. This is really a very good blog post and thanks for sharing it with the community!
    web design company in chennai

    ReplyDelete
  56. Hi,
    Thanks for sharing a very interesting article about The Test Lifecycle in 2.0. Looking forward to read about other blogs from you as well. Thanking you . Think To Share digital marketing team

    ReplyDelete
  57. Jede Person kann( máy xông tinh dầu ) unterschiedliche Gründe( máy xông hương tinh dầu ) haben, um ihr eigenes Leben( máy khuếch tán tinh dầu tphcm ) zu führen. Sie können nicht( Máy khuếch tán tinh dầu ) alle Gründe erfassen, die gleich sind

    ReplyDelete
  58. Your article is very interesting. Also visit our website at:
    web design company in chennai

    ReplyDelete
  59. This comment has been removed by the author.

    ReplyDelete
  60. Thank You.

    Freshpani is providing online water delivery service currently in BTM, Bangalore you can find more details at Freshpani.com
    Online Water Delivery | Bangalore Drinking Water Home Delivery Service | Packaged Drinking Water | Bottled Water Supplier

    ReplyDelete
  61. Bài viết rất hay: Chúng tôi chuyên cung cấp các sản phẩm chất lượng sau:



    bồn massage



    bon ngam chan



    máy massage chân



    Cảm ơn các bạn!

    ReplyDelete
  62. This comment has been removed by the author.

    ReplyDelete
  63. This comment has been removed by the author.

    ReplyDelete
  64. I really enjoyed your blog Thanks for sharing such an informative post.
    https://www.login4ites.com/

    ReplyDelete
  65. Informative post keep sharing the valuable post like this!!!

    piper | dataops platform

    ReplyDelete
  66. Wow, Great information and this is very useful for us.

    Aluminium scaffolding hire

    ReplyDelete
  67. This comment has been removed by the author.

    ReplyDelete
  68. This comment has been removed by the author.

    ReplyDelete
  69. This comment has been removed by the author.

    ReplyDelete
  70. Thanks for sharing nice information with us. I like your post and all you share with us is up to date and quite informative,

    Thanks
    Cpa offers

    ReplyDelete
  71. Le hair steamer permet de lutter contre la sécheresse, la chute des cheveux et leur mauvaise santé , dans le confort de votre domicile. Le hair steamer est un casque vapeur qui apporte une dose d'hydratation pour les cheveux crépus.
    hair steamer
    Le hair steamer pas cher livraison sur paris.
    Le hair steamer france livraison sur paris.

    ReplyDelete
  72. Nice information and its interesting to learn about robolectric
    keep posting Thanks
    web design company in Chennai

    ReplyDelete
  73. thanks for your information really good your work web design company in velachery Qbigpro branding solution is the best web design company in velachery web design company in velachery.we will create the web site and managing the site.we will help for all business.website is very important for all business.

    ReplyDelete
  74. thanks for your details it's very use for my works web design company in velachery Qbigpro branding solution is the best web design company in velachery web design company in velachery.we will create the web site and managing the site.we will help for all business.website is very important for all business.

    ReplyDelete
  75. La sciatique est une douleur vive ressentie le long d’un des 2 nerfs sciatiques. Situés à l’arrière de chacune des jambes, ce sont les nerfs les plus volumineux de l’organisme (voir schéma). Ils rejoignent la colonne vertébrale au bas du dos, à la hauteur des vertèbres lombaires et sacrées (tout juste au-dessus du coccyx) sciatique

    ReplyDelete

  76. wonderful article buddy...!!
    one of the best website development company i ever had.
    they do good and very unique.do visit this page and know
    more guys web portal development company in chennai

    ReplyDelete


  77. Beemainfratech are extremely immersed in manufacturing an inclusive range of Aluminium Scaffolding Dealers.
    they do good and very unique.do visit this page and know more guys Scaffolding Dealers in Chennai

    ReplyDelete
  78. Found useful information.

    I thought this article will help lots of developer who have been facing problem after new update of Robolectric 2.0 alpha 3.

    I know one mobile app development company in Bangalore which provides app development with latest technology.

    ReplyDelete
  79. Thanks for your article its really nice

    We are swotter technologies website designing company in chennai to build both static and dynamic website build.

    ReplyDelete
  80. Es fácil ganarse una confianza que( tam san be tong sieu nhe ) es fácil de destruir, es ( Sàn panel Đức Lâm ) importante no engañar a los grandes( nhà thép dân dụng ) o pequeños,( xây nhà bằng bê tông siêu nhẹ ) pero el engaño ha sido el problema

    ReplyDelete
  81. Software Development Company We specialize in Blockchain development, Artificial Intelligence, DevOps, Mobile App development, Web App development and all your customised online solutions. Get best impression at online by our services, we are familiar for cost effectiveness, quality, delivery and support.

    ReplyDelete
  82. Thanks for sharing such a great information with us.Keep on updating us with these types of blogs.
    professional web design company in chennai
    web design company in chennai

    ReplyDelete
  83. wonderful article buddy...!!
    one of the best website development company i ever had.
    they do good and very unique.do visit this page and know
    more about this guys Web portal development company in chennai

    one of their client site is now running succesfully,visit this site to know their working effort
    Aluminium scaffolding hire

    ReplyDelete
  84. Es fácil ganarse una confianza que( tam san be tong sieu nhe ) es fácil de destruir, es importante no engañar a los grandes( tấm bê tông siêu nhẹ ) o pequeños, pero el engaño ha sido el problema

    ReplyDelete
  85. This comment has been removed by the author.

    ReplyDelete
  86. Thanks for sharing such a great information with us.Keep on updating us with these types of blogs.
    professional web design company in chennai
    top 10 web designing companies in chennai

    ReplyDelete
  87. Thanks for provide great informatic and looking beautiful blog, really nice required information & the things i never imagined and i would request, wright more blog and blog post like that for us. Thanks you once agianMarriage certificate in delhi
    Marriage certificate in ghaziabad
    Marriage registration in gurgaon
    Marriage registration in noida
    special marriage act
    Marriage certificate online
    Marriage certificate in mumbai
    Marriage certificate in faridabad
    Marriage certificate in bangalore
    Marriage certificate in hyderabad thanks once again to all.

    ReplyDelete
  88. Thanks for provide great informatic and looking beautiful blog, really nice required information & the things i never imagined and i would request, wright more blog and blog post like that for us. Thanks you once agian

    special marriage act
    name add in birth certificate
    passport agent
    court marriage in delhi
    name change
    marriage registration
    birth certificate in gurgaon
    birth certificate in noida
    birth certificate in ghaziabad
    birth certificate in delhi

    ReplyDelete
  89. Thank you so much for this wonderful Post and all the best for your future. I hope to see more post from you. I am satisfied with the arrangement of your post.
    shot blasting machine
    shotblasting
    sandblasting
    sand blasting machine
    steel shots distributors
    Sandblasting Abrasive media

    ReplyDelete

  90. Awesome post. I am a normal visitor of your blog and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a long time.
    video production company
    production houses in delhi
    Corporate film makers
    Documentary Film Makers in Delhi
    Filmmakers in Delhi
    promotional video services in delhi ncr

    ReplyDelete
  91. Way cool! Some very valid points! I appreciate you penning this write-up and also the rest of the site is also really good.

    ACP Sheet
    ACP Sheet Price
    Aluminium Composite Panel
    ACP Panel
    ACP Sheets

    ReplyDelete

  92. Jeewangarg is a one-stop solution for all of your digital marketing needs whether to build your online presence or establish your own brand. We are specialized in building a website, doing Effective SEO for websites and providing the best Google Adwords Services and Digital Marketing Agency to our valuable clients. Though, there are numerous factors that separate us from any other SEO Services in Delhi, here are a few that we believe would not be too much to mention.

    ReplyDelete
  93. Emedkit are a global pharmaceutical company whose mission is to advance the well-being of people around the world especially in countries like India, USA, Russia, Romania, Peru, and China. Our products include treatments for diseases such as Ledifos tablets, HIV/AIDS, Cancer, Hepcinat Lp tablets, Cancer Medicine. We provide our products at the lowest possible price as we stock bulk qualities and we deal both in drop shipping and bulk shipping.

    Buy Hepcinat Lp tablets Online

    Liver Cancer Medicine

    Buy Alecensa 150 mg Tablet

    ReplyDelete
  94. Jeewangarg is one of the Best Digital Marketing Agencies where you can find each and every solution under one roof. We are efficient enough to provide our clients the best seo services in Delhi & PPC Services in Delhi at the same place. Moreover, we are the best website designing company in delhi ncr.

    ReplyDelete
  95. Thanks for sharing such a great information but we are India's best service provider of SBI Kiosk Banking - NICTCSP.

    sbi kiosk

    sbi csp

    ReplyDelete
  96. Thanks for sharing this informative post. Here we are presenting Chanson Water.
    Best alkaline water ionizer machine manufacturers in india.
    alkaline water machine
    water ionizer india

    ReplyDelete
  97. Nice post. Plan Your next Holidays with Indian Travel Store and get some Exciting Deals on Tours & Travels Packages for Shimla, Manali, Nepal, Bhutan, Rajasthan, Dalhousie, Dharamshala, Kerala, Uttarakhand and many more. Book your next Shimla Manali Tour Package with us for availing some great deals.

    Manali tour package
    Shimla manali tour package

    ReplyDelete
  98. Nice Blog, keep it up for more updates about this type of blog.Carolina Classics is the manufacturer of best F-100 Classic Ford Truck Parts | Buy Ford F100 truck parts online at Carolina Classics.

    Classic Ford Truck Parts
    F-100 Ford Truck Parts

    ReplyDelete