Roboletric 4.0.1 keeps throwing Resources$NotFoundException on buildActivity









up vote
0
down vote

favorite












I am trying to build very simple unittest with roboletric but I can't create the activity.



I tried what was suggested on the thread but no success.



Resources$NotFoundException when calling Robolectric.buildActivity()



Yet, I am using the 4.0.1 version. I wonder if there some extra setup that I need to do.



Here's is my gradle:



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'

testImplementation 'androidx.test.espresso:espresso-core:3.1.0'
testImplementation 'androidx.test:core:1.0.0'
testImplementation 'androidx.test.ext:junit:1.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation 'org.robolectric:robolectric:4.0.1'
androidTestImplementation 'com.google.truth:truth:0.42'
testImplementation 'com.google.truth:truth:0.42'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'



and my test program:



@Config(sdk = 28, manifest=Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class MainActivityTest
private Activity activity;
@Before
public void setup()

try
// I tried these 3 lines of code and they all throw the exception :(

//activity = Robolectric.buildActivity(MainActivity.class).create().get();
//activity = Robolectric.setupActivity(MainActivity.class);
activity = Robolectric.buildActivity(MainActivity.class).create().start().resume().get();

catch (Exception e)

System.out.println("Keeps throwing exception!");





here' the output:



[Robolectric] com.guitarv.robotest.MainActivityTest.validateTextViewContent: sdk=28; resources=legacy
[Robolectric] NOTICE: legacy resources mode is deprecated; see http://robolectric.org/migrating/#migrating-to-40
Keeps throwing exception!
Test:Sun Nov 11 06:21:59 PST 2018


I did click on that link and update the gradle.properties to:



org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableUnitTestBinaryResources=true


But no success. I still can't create the activity and the legacy mode message keeps showing up.



any clues what am I doing wrong?



thank you.










share|improve this question



















  • 1




    There is no need to use @Config(sdk = 28) as robolectric choose the SDK as the project default SDK which in your case i guess is 28 and . i faced a similar problem and solved by changing the test class SDK to 27 @Config(sdk = 27)
    – Omar Beshary
    Nov 12 at 19:30










  • I tried, and no success. What a difficult thing to get a simple test program to work :(
    – gmmo
    Nov 12 at 21:11






  • 1




    did you make sure of including android resources as mentioned in documentation ? testOptions unitTests includeAndroidResources = true
    – Omar Beshary
    Nov 12 at 21:52










  • that was it! thx!
    – gmmo
    Nov 12 at 22:38














up vote
0
down vote

favorite












I am trying to build very simple unittest with roboletric but I can't create the activity.



I tried what was suggested on the thread but no success.



Resources$NotFoundException when calling Robolectric.buildActivity()



Yet, I am using the 4.0.1 version. I wonder if there some extra setup that I need to do.



Here's is my gradle:



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'

testImplementation 'androidx.test.espresso:espresso-core:3.1.0'
testImplementation 'androidx.test:core:1.0.0'
testImplementation 'androidx.test.ext:junit:1.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation 'org.robolectric:robolectric:4.0.1'
androidTestImplementation 'com.google.truth:truth:0.42'
testImplementation 'com.google.truth:truth:0.42'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'



and my test program:



@Config(sdk = 28, manifest=Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class MainActivityTest
private Activity activity;
@Before
public void setup()

try
// I tried these 3 lines of code and they all throw the exception :(

//activity = Robolectric.buildActivity(MainActivity.class).create().get();
//activity = Robolectric.setupActivity(MainActivity.class);
activity = Robolectric.buildActivity(MainActivity.class).create().start().resume().get();

catch (Exception e)

System.out.println("Keeps throwing exception!");





here' the output:



[Robolectric] com.guitarv.robotest.MainActivityTest.validateTextViewContent: sdk=28; resources=legacy
[Robolectric] NOTICE: legacy resources mode is deprecated; see http://robolectric.org/migrating/#migrating-to-40
Keeps throwing exception!
Test:Sun Nov 11 06:21:59 PST 2018


I did click on that link and update the gradle.properties to:



org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableUnitTestBinaryResources=true


But no success. I still can't create the activity and the legacy mode message keeps showing up.



any clues what am I doing wrong?



thank you.










share|improve this question



















  • 1




    There is no need to use @Config(sdk = 28) as robolectric choose the SDK as the project default SDK which in your case i guess is 28 and . i faced a similar problem and solved by changing the test class SDK to 27 @Config(sdk = 27)
    – Omar Beshary
    Nov 12 at 19:30










  • I tried, and no success. What a difficult thing to get a simple test program to work :(
    – gmmo
    Nov 12 at 21:11






  • 1




    did you make sure of including android resources as mentioned in documentation ? testOptions unitTests includeAndroidResources = true
    – Omar Beshary
    Nov 12 at 21:52










  • that was it! thx!
    – gmmo
    Nov 12 at 22:38












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to build very simple unittest with roboletric but I can't create the activity.



I tried what was suggested on the thread but no success.



Resources$NotFoundException when calling Robolectric.buildActivity()



Yet, I am using the 4.0.1 version. I wonder if there some extra setup that I need to do.



Here's is my gradle:



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'

testImplementation 'androidx.test.espresso:espresso-core:3.1.0'
testImplementation 'androidx.test:core:1.0.0'
testImplementation 'androidx.test.ext:junit:1.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation 'org.robolectric:robolectric:4.0.1'
androidTestImplementation 'com.google.truth:truth:0.42'
testImplementation 'com.google.truth:truth:0.42'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'



and my test program:



@Config(sdk = 28, manifest=Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class MainActivityTest
private Activity activity;
@Before
public void setup()

try
// I tried these 3 lines of code and they all throw the exception :(

//activity = Robolectric.buildActivity(MainActivity.class).create().get();
//activity = Robolectric.setupActivity(MainActivity.class);
activity = Robolectric.buildActivity(MainActivity.class).create().start().resume().get();

catch (Exception e)

System.out.println("Keeps throwing exception!");





here' the output:



[Robolectric] com.guitarv.robotest.MainActivityTest.validateTextViewContent: sdk=28; resources=legacy
[Robolectric] NOTICE: legacy resources mode is deprecated; see http://robolectric.org/migrating/#migrating-to-40
Keeps throwing exception!
Test:Sun Nov 11 06:21:59 PST 2018


I did click on that link and update the gradle.properties to:



org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableUnitTestBinaryResources=true


But no success. I still can't create the activity and the legacy mode message keeps showing up.



any clues what am I doing wrong?



thank you.










share|improve this question















I am trying to build very simple unittest with roboletric but I can't create the activity.



I tried what was suggested on the thread but no success.



Resources$NotFoundException when calling Robolectric.buildActivity()



Yet, I am using the 4.0.1 version. I wonder if there some extra setup that I need to do.



Here's is my gradle:



dependencies 
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'

testImplementation 'androidx.test.espresso:espresso-core:3.1.0'
testImplementation 'androidx.test:core:1.0.0'
testImplementation 'androidx.test.ext:junit:1.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation 'org.robolectric:robolectric:4.0.1'
androidTestImplementation 'com.google.truth:truth:0.42'
testImplementation 'com.google.truth:truth:0.42'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'



and my test program:



@Config(sdk = 28, manifest=Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class MainActivityTest
private Activity activity;
@Before
public void setup()

try
// I tried these 3 lines of code and they all throw the exception :(

//activity = Robolectric.buildActivity(MainActivity.class).create().get();
//activity = Robolectric.setupActivity(MainActivity.class);
activity = Robolectric.buildActivity(MainActivity.class).create().start().resume().get();

catch (Exception e)

System.out.println("Keeps throwing exception!");





here' the output:



[Robolectric] com.guitarv.robotest.MainActivityTest.validateTextViewContent: sdk=28; resources=legacy
[Robolectric] NOTICE: legacy resources mode is deprecated; see http://robolectric.org/migrating/#migrating-to-40
Keeps throwing exception!
Test:Sun Nov 11 06:21:59 PST 2018


I did click on that link and update the gradle.properties to:



org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableUnitTestBinaryResources=true


But no success. I still can't create the activity and the legacy mode message keeps showing up.



any clues what am I doing wrong?



thank you.







unit-testing robolectric






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 21:15

























asked Nov 11 at 14:35









gmmo

6863935




6863935







  • 1




    There is no need to use @Config(sdk = 28) as robolectric choose the SDK as the project default SDK which in your case i guess is 28 and . i faced a similar problem and solved by changing the test class SDK to 27 @Config(sdk = 27)
    – Omar Beshary
    Nov 12 at 19:30










  • I tried, and no success. What a difficult thing to get a simple test program to work :(
    – gmmo
    Nov 12 at 21:11






  • 1




    did you make sure of including android resources as mentioned in documentation ? testOptions unitTests includeAndroidResources = true
    – Omar Beshary
    Nov 12 at 21:52










  • that was it! thx!
    – gmmo
    Nov 12 at 22:38












  • 1




    There is no need to use @Config(sdk = 28) as robolectric choose the SDK as the project default SDK which in your case i guess is 28 and . i faced a similar problem and solved by changing the test class SDK to 27 @Config(sdk = 27)
    – Omar Beshary
    Nov 12 at 19:30










  • I tried, and no success. What a difficult thing to get a simple test program to work :(
    – gmmo
    Nov 12 at 21:11






  • 1




    did you make sure of including android resources as mentioned in documentation ? testOptions unitTests includeAndroidResources = true
    – Omar Beshary
    Nov 12 at 21:52










  • that was it! thx!
    – gmmo
    Nov 12 at 22:38







1




1




There is no need to use @Config(sdk = 28) as robolectric choose the SDK as the project default SDK which in your case i guess is 28 and . i faced a similar problem and solved by changing the test class SDK to 27 @Config(sdk = 27)
– Omar Beshary
Nov 12 at 19:30




There is no need to use @Config(sdk = 28) as robolectric choose the SDK as the project default SDK which in your case i guess is 28 and . i faced a similar problem and solved by changing the test class SDK to 27 @Config(sdk = 27)
– Omar Beshary
Nov 12 at 19:30












I tried, and no success. What a difficult thing to get a simple test program to work :(
– gmmo
Nov 12 at 21:11




I tried, and no success. What a difficult thing to get a simple test program to work :(
– gmmo
Nov 12 at 21:11




1




1




did you make sure of including android resources as mentioned in documentation ? testOptions unitTests includeAndroidResources = true
– Omar Beshary
Nov 12 at 21:52




did you make sure of including android resources as mentioned in documentation ? testOptions unitTests includeAndroidResources = true
– Omar Beshary
Nov 12 at 21:52












that was it! thx!
– gmmo
Nov 12 at 22:38




that was it! thx!
– gmmo
Nov 12 at 22:38












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Robolectric can't find your app's resources.



Add this to your build.gradle:



android 
testOptions
unitTests.includeAndroidResources = true




Add this to your gradle.properties (not necessary with Android Studio 3.3+):



android.enableUnitTestBinaryResources=true





share|improve this answer




















  • thank you! I was super stuck!
    – gmmo
    Nov 12 at 22:46










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249752%2froboletric-4-0-1-keeps-throwing-resourcesnotfoundexception-on-buildactivity%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Robolectric can't find your app's resources.



Add this to your build.gradle:



android 
testOptions
unitTests.includeAndroidResources = true




Add this to your gradle.properties (not necessary with Android Studio 3.3+):



android.enableUnitTestBinaryResources=true





share|improve this answer




















  • thank you! I was super stuck!
    – gmmo
    Nov 12 at 22:46














up vote
0
down vote



accepted










Robolectric can't find your app's resources.



Add this to your build.gradle:



android 
testOptions
unitTests.includeAndroidResources = true




Add this to your gradle.properties (not necessary with Android Studio 3.3+):



android.enableUnitTestBinaryResources=true





share|improve this answer




















  • thank you! I was super stuck!
    – gmmo
    Nov 12 at 22:46












up vote
0
down vote



accepted







up vote
0
down vote



accepted






Robolectric can't find your app's resources.



Add this to your build.gradle:



android 
testOptions
unitTests.includeAndroidResources = true




Add this to your gradle.properties (not necessary with Android Studio 3.3+):



android.enableUnitTestBinaryResources=true





share|improve this answer












Robolectric can't find your app's resources.



Add this to your build.gradle:



android 
testOptions
unitTests.includeAndroidResources = true




Add this to your gradle.properties (not necessary with Android Studio 3.3+):



android.enableUnitTestBinaryResources=true






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 22:28









Xian

864179




864179











  • thank you! I was super stuck!
    – gmmo
    Nov 12 at 22:46
















  • thank you! I was super stuck!
    – gmmo
    Nov 12 at 22:46















thank you! I was super stuck!
– gmmo
Nov 12 at 22:46




thank you! I was super stuck!
– gmmo
Nov 12 at 22:46

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249752%2froboletric-4-0-1-keeps-throwing-resourcesnotfoundexception-on-buildactivity%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric