6

I am new to Roboelectric testing. I am trying to follow this post to test fragments. I am using following as dependency

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile "org.robolectric:robolectric:3.0"
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:support-v4:22.1.0'
compile 'com.google.android.gms:play-services:7.5.0'

}

But this import is giving me compilation issues, and I am not able to resolve the symbol SupportFragmentTestUtil to start with. Kindly guide me what I am missing??

org.robolectric.shadows.support.v4.SupportFragmentTestUtil
Community
  • 1
  • 1
indi mars
  • 133
  • 3
  • 8
  • Do not copy and paste. Use `SupportFragmentTestUtil` with `testCompile "org.robolectric:robolectric:3.0"` – Jared Burrows Aug 07 '15 at 04:04
  • Thanks Jared for your interest. I have updated my problem. I am surprised , I dont see this import , there is no support package – indi mars Aug 07 '15 at 10:44
  • Please see @Nicks answer. – Jared Burrows Aug 07 '15 at 13:41
  • ohhh great, it worked. But shouldn't this be documented somewhere for android newbies like me. – indi mars Aug 08 '15 at 08:04
  • It shouldnt be documented? You mean it should? It is on the robolectric wiki on github. – Jared Burrows Aug 08 '15 at 14:04
  • Hi Jared, can you point me the link. I happened to see https://github.com/robolectric/robolectric and http://robolectric.org/getting-started/ and in both links, nowhere i was able to figure out the use of support library dependency.It will be helpful for me for future reference. – indi mars Aug 11 '15 at 10:24
  • Here: https://github.com/robolectric/robolectric/wiki/2.4-to-3.0-Upgrade-Guide – Jared Burrows Aug 11 '15 at 14:03
  • guys!!! can you guide me in this issue? http://stackoverflow.com/questions/32499667/simpletestcursor-robolectric-3-0-compilation-issue – indi mars Sep 10 '15 at 10:43
  • For more information/background, see this question: http://stackoverflow.com/questions/11333354/how-can-i-test-fragments-with-robolectric/12903280#12903280 – colabug Jan 20 '16 at 13:45

1 Answers1

11

You need to add the dependency for v4 shadows support. Add this in your dependency file.

testCompile "org.robolectric:shadows-support-v4:3.0"
ThomasW
  • 16,981
  • 4
  • 79
  • 106
Nicks
  • 16,030
  • 8
  • 58
  • 65
  • Thanks! I updated my question with this information: http://stackoverflow.com/questions/11333354/how-can-i-test-fragments-with-robolectric/12903280#12903280 – colabug Jan 20 '16 at 13:44