So I started with a UnitTest called MyCoolObjectTest. Needing to do some instrumentation testing, I moved the class right within the Android
project view from the test
directory to the androidTest
directory by dragging. My UnitTest used to work fine; except for the instrumentation portions. But now it does not work at all. I keep getting
Class not found: "com.mypkg.MyCoolObjectTest"Empty test suite.
I have been looking all over stackOverflow and at the official docs for a solution. No luck so far. Has anyone experienced something similar?
(if I drag it back to the test folder it works; if I re-drag to the androidTest folder it stops working again)
I remember the was a way to set the folder under test. But I no longer remember.
For some insight, I want to use some android library in my test such as
public String stripFormatting(String input){
return Html.fromHtml(input).toString();
}
That's why I need instrumentation.
Here is my unit test class with one test for an example:
@RunWith(AndroidJUnit4.class)
public class MyCoolObjectTest {
@Test
public void testJustToKnow() {
String actual = "<b>0</b>";
String expected = "0";
assertThat(stripFormatting(actual), equalTo(expected));
}
public String stripFormatting(String input) {
return Html.fromHtml(input).toString();
}
}
update
Here is a different trace that I got. If I click on the method instead of the class, I get the following trace:
Just now I clicked on the method instead of the whole class, and got the following trace:
11/04 13:51:16: Launching testJustToKnow() $ adb push /Users/me/StudioProjects/Myapp/app/build/outputs/apk/app-debug.apk /data/local/tmp/com.mypkg.myapp $ adb shell pm install -r "/data/local/tmp/com.mypkg.myapp" pkg: /data/local/tmp/com.mypkg.myapp Success
$ adb push /Users/me/StudioProjects/Myapp/app/build/outputs/apk/app-debug-androidTest-unaligned.apk /data/local/tmp/com.mypkg.Myapp.test $ adb shell pm install -r "/data/local/tmp/com.mypkg.myapp.test" pkg: /data/local/tmp/com.mypkg.myapp.test Success
Running tests
$ adb shell am instrument -w -r -e debug false -e class com.mypkg.myapp.utils.MyCoolObjectTest#testJustToKnow com.mypkg.myapp.test/android.test.InstrumentationTestRunner Client not ready yet..Test running started
junit.framework.AssertionFailedError: No tests found in com.mypkg.myapp.utils.MyCoolObjectTest at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1959)
Tests ran to completion.
I just had the same problem. Here is how I solved it:
Everything should work now.
Maybe this will be useful:
src/test: only for unit test (nothing that involve android framework).
src/androidTest: for android instrumentation tests.
Please see here a better explanation for this.
Example of instrumentation test (Please check your annotations, for example @RunWith(AndroidJUnit4.class)
or @SmallTest
or @Test
)
I hope this will be useful for you.
(update)
Maybe you forgot this on your gradle (in the main module):
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
If you has using Espresso, you must add a dependency (Please check the link above this "...Example of instrumentation test...")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With