4

I'm new at Android testing and I'm trying to test a custom view in an android library and i'm using Android Studio.

I found here : Android: How to test a custom view? that I should use ActivityUnitTestCase and a mock activity. I have put my xml layout inside projectname/library/src/androidTest/res/layout and my test activity know my layout R id thanks to this : Configuring res srcDirs for androidTest sourceSet. My issues is in the layout content.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <eu.custom.customView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
</RelativeLayout>

In my case, "http://schemas.android.com/apk/res/android" display in red with an error "URI not registered" and the IDE doe's not recognize my custom view if I add it in this xml.

Is there a way to have this layout working without putting it in production code ?

Thanks

Community
  • 1
  • 1
Will Bobo
  • 408
  • 4
  • 11

1 Answers1

0

Well, in my Eclipse IDE your code looks correct (there are no red lines) may I suggest you to download the ADT-Bundle again or use Android Studio? I think your IDE is corrupted or something in your settings is wrong. Also check if you have downloaded the up-to-date SDK build tools.

  • So you can create and use layout in the android test folder ? I edited the question, I forgot to tell that I use android studio. And everything is up to date. I don't think it's the code itself that is wrong but maybe some test configuration or limitation. – Will Bobo Jul 09 '15 at 15:18
  • I would suggest you to don't use test folder at all, try first editing it in main :) –  Jul 09 '15 at 18:05
  • Of course it works if I don't use the test folder. But it seems so wrong to me to have xml layout only for testing in the main folder. – Will Bobo Jul 10 '15 at 12:37
  • Anything on this ? Im facing similar on Android Studio 3.3 and im trying to create a test only resource – onusopus Mar 28 '19 at 23:24