所以我开始使用名为MyCoolObjectTest的UnitTest。需要做一些仪器测试,我通过拖动将Android
项目视图中的课程从test
目录移动到androidTest
目录。我的单元测试用于正常工作;仪器部分除外。但现在它根本不起作用。我一直收到在Android Studio中将UnitTest转换为Instrumentation测试
Class not found: "com.mypkg.MyCoolObjectTest"Empty test suite.
我一直在寻找所有的stackoverflow和官方文档的解决方案。到目前为止没有运气。有没有人遇到类似的东西?
(如果我拖回到它的工作原理test文件夹;如果我再拖动它再次停止工作androidTest文件夹)
我记得是到文件夹设置下测试的方式。但我不记得了。
对于一些见解,我想用一些Android库里在我的测试,如
public String stripFormatting(String input){
return Html.fromHtml(input).toString();
}
这就是为什么我需要的仪器。
这里是我的单元测试类的一个实例一个测试:
@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();
}
}
更新
这是一个不同的跟踪,我得到了。如果我点击的方法,而不是类,我得到以下跟踪:
我刚才点击的方法,而不是整个班级,并得到了以下跟踪:
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.
你可以发布测试课吗? –