Create DummyActivity inside androidTest folder for testing

There are 2 APK generated during project building. First is APK with application and second APK contains test. If you put your activity in test folder it will be in second APK that is used for test and your application APK does not contains it. This is why you are receiving this error (because your application APK does not have such activity).

So the only way for you is to put your activity not in test folder but in sources. You can create several application variants (see details here), so when you are building your APK in production your dummy activity will not be included in it.


I already answered this question here and places a link to a simple project that implements it, so you can even see the complete source code for that :-) I'll copy my of the answer here, because it seems that I achieved your goal:

That's easy! In general, you should just put your resources under the src/androidTest/res folder. And that is! Then you can use it in your src/androidTest/java files. Yes, you can't use test layouts in your production APK, but you can use your test layouts in your test APK.

There're some problems that might confuse you. For instance autocompletion works well not so very often, but, anyway, it builds and works.

It's the complete test tree, so you can see that I have that activity inside the test project and don't pollute the main one :-) Feel free to ask questions if something is still wrong :-)

$ tree androidTest/
androidTest/
├── AndroidManifest.xml
├── java
│   └── ru
│       └── egslava
│           └── lib_phone
│               ├── MainActivityTest.java
│               ├── TestActivity.java
│               └── actions
│                   ├── HintViewAction.java
│                   ├── KeepHintViewAction.java
│                   └── SetTextViewAction.java
└── res
    ├── layout
    │   └── activity_main.xml
    └── values
        └── styles.xml

And, yes, I can't answer your particular question because on my side everything works and I can't see your complete project :-) I just want to say that it works and you definitely don't need to move your test activities to non-test projects. Feel free to ask questions / post the code :-)