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.