Android TDD and Roboelectric

Android TDD and Roboelectric

I have been learning about Android development and test-driven development lately, came across the Roboelectric framework and its concept of running tests inside JVM

So, basically during development when you are practicing Red Green Refactoring you need to run tests multiple times and it would be a great hassle for the Android development since all the time emulator will start, it eventually costs you a lot of time and effort. Even it leads developers to miss scenarios and test cases.

Roboelectric helps a lot to follow TDD as it makes it much more simple and convenient, as compared to JUnit which usually be the choice of most of the developers, but it's not solely focused on android and the general flow is you need to build, deploy and launch the app which obviously takes some time, and not efficient during development. So, the Roboelectric framework refines this by running inside the JVM on the workstation in seconds which is much faster. So, because of this, the dexing, packaging, and installing-on-the emulator steps aren’t necessary, reducing test cycles from minutes to seconds, so you can iterate quickly and refactor your code with confidence.

The other alternative of Robolectric is to use mocking frameworks like Mockito for mocking out the android SDK but Roboelectric has its own advantages as it focuses on the behavior of the application instead of the implementation which makes it more effective in refactoring.

Simple test written using Roboelectric is,

@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {


? @Test
? public void clickingButton_shouldChangeMessage() {
? ? MyActivity activity = Robolectric.setupActivity(MyActivity.class);


? ? activity.button.performClick();


? ? assertThat(activity.message.getText()).isEqualTo("Robolectric Rocks!");
? }
}        

Learn More :

Would love to know your thoughts!


Fakhar Ud Din Khokhar

SDET Professional | Enhancing Agile Teams with Scalable Testing Frameworks and Robust Automation

2 年

nice ??

回复

要查看或添加评论,请登录

Syed Rehan Ahmed的更多文章

  • Automating Web Performance - Google Page Speed Insights API

    Automating Web Performance - Google Page Speed Insights API

    Website Performance One of the key factor for web performance is the how long it take to load page, reder resources…

    1 条评论
  • Android Applications Testing - Helpful Tools

    Android Applications Testing - Helpful Tools

    For the Mobile Apps Testers, there are areas where we need to go beyond the functional testing part, as its just one…

    2 条评论
  • Test Driven Development & Role of QA

    Test Driven Development & Role of QA

    Software development is an evolving field, theres always new trends and technology enhancements with every new day, in…

    1 条评论
  • Testing Asynchronous Systems

    Testing Asynchronous Systems

    Learning how async systems work and how to get them tested, I came across a Java Library (framework) that makes it…

    2 条评论

社区洞察

其他会员也浏览了