我有listview的自定义布局,我想点击列表视图项中的imageview,列表视图中第一项的溢出图标.
我想点击ID为"rcOverflow"的最后一张imageview
我的布局,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingTop="5dp">
<ImageView
android:id="@+id/rcCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/rcTime"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="right"
android:maxLines="1"
android:textColor="#ffffff"
android:textSize="13sp" />
<RelativeLayout
android:id="@+id/rsBubble"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/recordsMonthHeader"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<ImageView
android:id="@+id/rcImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_alignParentTop="true"
android:visibility="gone"
android:layout_marginLeft="3dp"
android:layout_marginRight="4dp"/>
<TextView
android:id="@+id/rcFilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:textColor="#000000"
android:maxLines="2"
android:ellipsize="end"
android:textSize="15sp" />
<TextView
android:id="@+id/rcDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/recordsFilename"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:textColor="#a09f9f" />
<ImageView
android:id="@+id/records_location_image"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignBottom="@id/recordsDuration"
android:layout_marginBottom="4dp" />
<TextView
android:id="@+id/rcLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/recordsDuration"
android:layout_marginBottom="1dp"
android:layout_marginLeft="3dp" …Run Code Online (Sandbox Code Playgroud) 我在单元测试时遇到以下错误 -
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
Run Code Online (Sandbox Code Playgroud)
项目结构是-

经过对运行配置的一些调查后,发现它在运行此单元案例时采用了错误的模块(main.java.com.example.dexter.sunshine.app)。我们如何更改这个模块?
如何android.support.test.*在AS中附加源代码进行调试?
尝试从https://android.googlesource.com/platform/frameworks/testing下载源代码,但该版本似乎与我的测试库版本不匹配.
测试源(例如AndroidJunitRunner)似乎没有通过sdk管理器提供,我错过了什么?
我正在尝试设置一个类似于Android 测试蓝图中描述的测试项目,但我收到以下 NoClassDefFoundError:
java.lang.NoClassDefFoundError: android.test.mock.MockContentResolver
Run Code Online (Sandbox Code Playgroud)
Android Studio 正确解决了这个问题,但是在运行时我收到了这个错误。
值得注意的是,我在应用程序项目上没有 androidTest 配置,相反我只有一个单独的tests模块:
apply plugin: 'com.android.test'
Run Code Online (Sandbox Code Playgroud)
我正在运行这样的测试:
./gradlew :tests:connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)
可以在此处找到重现此问题的测试项目:https : //github.com/vexdev/android-testing-templates/tree/master/AndroidTestingBlueprint
编辑:也在Android 开发社区上询问
编辑:还创建了以下 android 问题:https : //code.google.com/p/android/issues/detail?id=200182&thanks=200182&ts=1454489567
嗨,我遇到了当我在 androidTest 清单文件中重写应用程序时,它不起作用。这是我AndroidManifest.xml在androidTest文件夹中的文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.app"
android:installLocation="auto">
<application
tools:replace="android:name"
android:name=".app.ApplicationAndroidTest" />
</manifest>
Run Code Online (Sandbox Code Playgroud)
这是原来的一部分AndroidManifest.xml,从main文件夹中:
<application
android:name=".app.Application"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/Theme">
...
</application>
Run Code Online (Sandbox Code Playgroud)
事实上,我调试了它,并从被测活动的断点调用 getApplication(),它返回.app.Application而不是ApplicationAndroidTest实例。
你知道为什么 androidTest 中的 android manifest 文件会被忽略吗?
在我的测试用例中,我想获得我在片段场景中启动的片段的视图,如下所示:
val scenario = launchFragment<MyFragment>()
在MyFragment我有一个rootView返回片段的绑定视图的方法。在我的测试中,我想获取根视图并将其保存在另一个字段中。这是我已经尝试过的
val rootView: ViewGroup? = null
val scenario = launchFragment<MyFragment>()
scenario.onFragment { fragment -> fragment.rootView {
rootView = fragment.rootView
}
Run Code Online (Sandbox Code Playgroud)
如何从片段场景中保存视图?
我正在尝试使用 Koin 进行一些测试,但是我收到了“未解析的参考:KoinTest”但是,似乎正在正确执行导入,因为我看不到代码中的任何错误。仅在我尝试时运行测试。
我尝试清理并重建项目并重新启动 android studio,但问题仍然存在
测试班
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.test.KoinTest
import salva.perez.cabify.di.applicationModule
import org.koin.test.inject
class VoucherPresenterTest : KoinTest {
private val presenter: VoucherContract.Presenter by inject()
@Before
fun before() {
startKoin {
modules(applicationModule)
}
}
@After
fun after() {
stopKoin()
}
@Test
fun testInitViewCorrectly() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
摇篮
implementation 'org.koin:koin-android:2.0.1'
testImplementation 'org.koin:koin-test:2.0.1'
Run Code Online (Sandbox Code Playgroud) 导入库,比如androidx.test:core:1.2.0,androidx.test.ext:truth:1.2.0,com.google.truth:truth:0.44,等进入当地的JUnit命名测试类ExampleUnitTest.kt。
未解决的参考:测试
示例UnitTest.kt
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import com.google.common.truth.Truth.assertThat
Run Code Online (Sandbox Code Playgroud) 预期- 创建一个 JUnit 5Extension类以管理TestCoroutineDispatcher.
观察到- 无法访问testDispatcher在Extension类中创建的变量。
测试.kt
@ExtendWith(InstantExecutorExtension::class, MainCoroutineExtension::class)
class FeedLoadContentTests {
private val contentViewModel = ContentViewModel()
private fun FeedLoad() = feedLoadTestCases()
@ParameterizedTest
@MethodSource("FeedLoad")
@ExtendWith(MainCoroutineExtension::class)
fun `Feed Load`(test: FeedLoadContentTest) = testDispatcher.runBlockingTest {
// Some testing done here.
}
}
Run Code Online (Sandbox Code Playgroud)
扩展.kt
class MainCoroutineExtension : BeforeEachCallback, AfterEachCallback {
val testDispatcher = TestCoroutineDispatcher()
override fun beforeEach(context: ExtensionContext?) {
Dispatchers.setMain(testDispatcher)
}
override fun afterEach(context: ExtensionContext?) {
Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用 androidTest、mokito 和 espresso 来测试 android 中的导航,就像本教程中建议的那样:\n https://developer.android.com/guide/navigation/navigation-testing \n但是我系统地收到以下错误: \n E/MonitoringInstr: 遇到异常:Thread[main,5,main]。将线程状态转储到输出并锁定峡湾。\n java.lang.RuntimeException: androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity@fa3e8be 必须实现 OnFragmentInteractionListener
\n\n这是测试类:
\n\npackage developer.android.com.enlightme\n\nimport androidx.fragment.app.testing.launchFragmentInContainer\nimport androidx.navigation.NavController\nimport androidx.navigation.Navigation\nimport androidx.test.espresso.Espresso.onView\nimport androidx.test.espresso.action.ViewActions\nimport androidx.test.espresso.matcher.ViewMatchers\nimport androidx.test.espresso.matcher.ViewMatchers.withId\nimport androidx.test.filters.MediumTest\nimport androidx.test.runner.AndroidJUnit4\nimport org.junit.Assert.*\nimport org.junit.Test\nimport org.junit.runner.RunWith\nimport org.mockito.Mockito.*\n\n\n@MediumTest\n@RunWith(AndroidJUnit4::class)\nclass MainFragmentTest{\n @Test\n fun createDebateTransition(){\n // Create a mock NavController\n val mockNavController = mock(NavController::class.java)\n // Create a graphical FragmentScenario for the TitleScreen\n var mainScenario = launchFragmentInContainer<MainFragment>()\n // Set the NavController property on the fragment\n mainScenario.onFragment { fragment -> Navigation.setViewNavController(fragment.requireView(), mockNavController)\n }\n // Verify that performing a click …Run Code Online (Sandbox Code Playgroud) android ×10
android-testing ×10
junit ×3
junit4 ×2
kotlin ×2
androidx ×1
fragment ×1
junit5 ×1
koin ×1
ui-testing ×1