How to mock/stub objects in robolectric tests?

Evgenii

What's the preferred way to mock/stub objects in robolectric tests?

My goal is to write Android code in TDD manner. Right now I am using interfaces and create mock classes that implement those interfaces in tests. This process is time consuming. Is there an easier way to stub a method of existing class in robolectric?

nenick

I can only post my opinion about that topic.

My preferred way is the MVP pattern.

  • java classes where you mock away views (android stuff) and test pure logic
  • android classes where i mock my presenter and similar classes, the initialisation will be done by robolectric with just create phase. most view methods are just delegator.

the second point works great because robolectric deliver already "stub" classes. all what i can't check with pure android will be checkable with shadow classes.

But maybe you just search for the Shadow classes functionality, http://robolectric.org/custom-shadows/ where you can stub methods.

Update: here is also an example how I do it https://github.com/nenick/android-gradle-template/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to mock/stub objects in robolectric tests?

From Dev

How to debug when running Robolectric tests in Android Studio?

From Dev

Writing Android acceptance tests with robolectric: how could it be done?

From Dev

How to debug when running Robolectric tests in Android Studio?

From Dev

Freezing time in Robolectric tests

From Dev

Robolectric tests not running (Android)

From Dev

Run robolectric tests in order?

From Dev

Using assets in robolectric tests

From Dev

Freezing time in Robolectric tests

From Dev

Robolectric tests not running (Android)

From Dev

Robolectric and Google Analytics Error on Tests

From Dev

Robolectric inflating custom views for tests

From Dev

Is it possible to do integration tests with Robolectric?

From Dev

Using the Android KeyStore in Robolectric tests

From Dev

Using the Android KeyStore in Robolectric tests

From Dev

Robolectric and Google Analytics Error on Tests

From Dev

How to test routes in Laravel 5, or Trying to "MockStub" something, or I have no idea of TDD

From Dev

How to test equality of two objects in unit tests?

From Dev

How to reuse mock objects in Perl unit tests?

From Dev

Android - Jacoco code coverage ignores Robolectric tests

From Dev

JaCoCo doesn't work with Robolectric tests

From Dev

Robolectric unit tests fail after Multidex

From Dev

Android gradle build that code coverage for robolectric tests

From Dev

AndroidStudio Robolectric Unit Tests - Invaild default

From Dev

Robolectric tests running in Android Studio but not on the command line

From Dev

Android - Jacoco code coverage ignores Robolectric tests

From Dev

How to turn on robolectric logging

From Dev

How to use findViewById() in robolectric

From Dev

How to override Robolectric application?

Related Related

  1. 1

    How to mock/stub objects in robolectric tests?

  2. 2

    How to debug when running Robolectric tests in Android Studio?

  3. 3

    Writing Android acceptance tests with robolectric: how could it be done?

  4. 4

    How to debug when running Robolectric tests in Android Studio?

  5. 5

    Freezing time in Robolectric tests

  6. 6

    Robolectric tests not running (Android)

  7. 7

    Run robolectric tests in order?

  8. 8

    Using assets in robolectric tests

  9. 9

    Freezing time in Robolectric tests

  10. 10

    Robolectric tests not running (Android)

  11. 11

    Robolectric and Google Analytics Error on Tests

  12. 12

    Robolectric inflating custom views for tests

  13. 13

    Is it possible to do integration tests with Robolectric?

  14. 14

    Using the Android KeyStore in Robolectric tests

  15. 15

    Using the Android KeyStore in Robolectric tests

  16. 16

    Robolectric and Google Analytics Error on Tests

  17. 17

    How to test routes in Laravel 5, or Trying to "MockStub" something, or I have no idea of TDD

  18. 18

    How to test equality of two objects in unit tests?

  19. 19

    How to reuse mock objects in Perl unit tests?

  20. 20

    Android - Jacoco code coverage ignores Robolectric tests

  21. 21

    JaCoCo doesn't work with Robolectric tests

  22. 22

    Robolectric unit tests fail after Multidex

  23. 23

    Android gradle build that code coverage for robolectric tests

  24. 24

    AndroidStudio Robolectric Unit Tests - Invaild default

  25. 25

    Robolectric tests running in Android Studio but not on the command line

  26. 26

    Android - Jacoco code coverage ignores Robolectric tests

  27. 27

    How to turn on robolectric logging

  28. 28

    How to use findViewById() in robolectric

  29. 29

    How to override Robolectric application?

HotTag

Archive