我打算用来FragmentScenario单独测试片段。在此片段中,我正在访问父活动以调用一些方法。为此,我正在使用CommonActivityOperations接口。我在此应用程序中使用导航架构组件。
interface CommonActivityOperations {
fun closeSearchBar()
fun navigateBackWithResult(resultFor: String, result: Bundle)
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在我的设备上运行测试时,AttractionDestinationFragment出现以下错误。
java.lang.ClassCastException: androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity cannot be cast to .interfaces.CommonActivityOperations
景点目的地片段
const val DESTINATION_DATA_EXTRA = "destination_data_result"
class AttractionDestinationFragment : BaseFragment(), ItemClickListener, ToolbarSearchChangeListener{
private lateinit var navigationController: NavController
private lateinit var defaultAttractionList: MutableList<AttractionDestinations>
private lateinit var attractionDestinationRecyclerViewAdapter: AttractionDestinationRecyclerViewAdapter
private val viewModel by lazy { getViewModel<AttractionDestinationViewModel>() }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_attraction_destination, container, false)
}
override fun onViewCreated(view: View, …Run Code Online (Sandbox Code Playgroud) 在使用 espresso 时,我经常遇到这样的情况:espresso 被卡住(例如 on onView(withId(R.id.somebutton)).perform(click()))等待所有资源空闲,据我所知,这些资源可以是动画、后台任务、队列中的可运行项等。目前我收到的唯一消息是:
E/TestRunner: androidx.test.espresso.PerformException: Error performing 'single click - At Coordinates: 359, 1291 and precision: 16, 16' on view 'with id: com.example:id/somebutton'.
(...)
Caused by: androidx.test.espresso.AppNotIdleException: Looped for 7 iterations over 60 SECONDS. The following Idle Conditions failed .
Run Code Online (Sandbox Code Playgroud)
该应用程序非常复杂,有什么可以帮助缩小导致 espresso 认为该应用程序不空闲的原因吗?
android android-testing android-espresso android-orchestrator
我正在尝试使用 uiautomator 所以查看了这里的教程https://developer.android.com/training/testing/ui-testing/uiautomator-testing#java
在教程中,它说:
在 Android 应用程序模块的 build.gradle 文件中,您必须设置对 UI Automator 库的依赖项引用:
dependencies {
...
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
Run Code Online (Sandbox Code Playgroud)
所以我添加了该行,所以我的 build.gradle 文件如下所示:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// androidTestImplementation('androidx.test.uiautomator:uiautomator:2.2.0')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files …Run Code Online (Sandbox Code Playgroud) android android-testing android-studio android-gradle-plugin
我正在尝试测试我的封装翻译器类,该类在底层使用Google ML Kit Translate 。我收到一个错误,抛出java.lang.IllegalStateException: This job has not completed yet. 我不太明白为什么会出现这个异常。有人有想法吗?
import com.google.common.truth.Truth.assertThat\nimport kotlinx.coroutines.CoroutineDispatcher\nimport kotlinx.coroutines.Dispatchers\nimport kotlinx.coroutines.ExperimentalCoroutinesApi\nimport kotlinx.coroutines.runBlocking\nimport kotlinx.coroutines.test.TestCoroutineDispatcher\nimport kotlinx.coroutines.test.resetMain\nimport kotlinx.coroutines.test.runBlockingTest\nimport kotlinx.coroutines.test.setMain\nimport org.junit.Before\nimport org.junit.Rule\nimport org.junit.Test\nimport org.junit.rules.TestWatcher\nimport org.junit.runner.Description\nimport timber.log.Timber\nimport kotlin.coroutines.resume\nimport kotlin.coroutines.suspendCoroutine\n\nclass GoogleMLKitTranslatorTest {\n\n private lateinit var translator: GoogleMLKitTranslator\n\n private val testValue = "Bana herhangi bir \xc5\x9fey sor"\n\n @get:Rule\n var coroutinesTestRule = CoroutineTestRule()\n\n @Before\n fun setup() {\n translator = GoogleMLKitTranslator()\n translator.initialize()\n\n Timber.plant(Timber.DebugTree())\n }\n\n @Test\n fun translate_turkish_test_to_english_should_return_true() =\n coroutinesTestRule.testDispatcher.runBlockingTest {\n val expectedValue = "Ask me anything"\n\n val translatedText …Run Code Online (Sandbox Code Playgroud) android kotlin android-testing kotlin-coroutines google-mlkit
我有一个包含输入字段和其下方的按钮的网络视图(网络视图是第 3 方代码)当我在手机上打开视图时,只要在字段中插入数字,按钮就会更改颜色并启用。
输入字段是
<input type="tel" name="input" id="input" class="inputbox" autocomplete="off" placeholder="number" value="">
Run Code Online (Sandbox Code Playgroud)
当我使用 Espresso 运行自动测试时,我可以将文本放入字段中,但按钮未启用
onWebView().withElement(findElement(Locator.ID, "input"))
.perform(clearElement())
.perform(DriverAtoms.webKeys("22222222"))
.perform(webClick())
.withElement(findElement(Locator.ID, "continueButton"))
.perform(webClick());
Run Code Online (Sandbox Code Playgroud)
Firefox 检查器显示 onChange 事件有一个事件侦听器,我认为其侦听器是这样的:
function(e) {
e.persist();
var t = /^[0-9\b]+$/;
d((function(a) {
return Object(c.a)(Object(c.a)({}, a), {}, Object(M.a)({}, e.target.name, t.test(e.target.value) ? e.target.value : e.target.value.replace(/[^0-9]/g, "")))
})), e.target.value.replace(/[^0-9]/g, "").length > 0 ? (j(!1), b("primary"), k(""), R("")) : (b("primary disabled"), k("hidden"), R("paddingTop20"))
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试触发 onchange 但没有运气:
onWebView().forceJavascriptEnabled().withElement(findElement(Locator.ID, "input"))
.perform(clearElement())
.perform(webClick())
.perform(DriverAtoms.webKeys("22222222"))
.perform(webClick())
.perform(SimpleAtom("function(elem) {\n" +
"var e = document.createEvent('Event');\n" …Run Code Online (Sandbox Code Playgroud) 我想以一种可以InstrumentationRegistry.getInstrumentation()在运行时访问的方式运行 Android 应用程序。
这仅适用于调试版本,通过 ADB 安装应用程序就足够了。因为我不想使用仪器测试套件,所以我不想使用InstrumentationTestRunner但直接启动MainActivity应用程序。
这怎么可能?
我尝试过的:
implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
implementation 'androidx.test:runner:1.1.0'
Run Code Online (Sandbox Code Playgroud)
<instrumentation android:name=".MainActivity"
android:targetPackage="com.android.shell"
android:label="App" />
Run Code Online (Sandbox Code Playgroud)
(不确定这是否真的正确。)
adb shell am instrument -w com.example.app/.MainActivity
Run Code Online (Sandbox Code Playgroud)
这导致:
android.util.AndroidException: INSTRUMENTATION_FAILED: com.example.app/com.example.app.MainActivity
at com.android.commands.am.Instrument.run(Instrument.java:519)
at com.android.commands.am.Am.runInstrument(Am.java:202)
at com.android.commands.am.Am.onRun(Am.java:80)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:60)
at com.android.commands.am.Am.main(Am.java:50)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:399)
Run Code Online (Sandbox Code Playgroud)
UiAutomator所以本质上我的问题是,如何以我可以在运行时使用的方式运行应用程序?
提前致谢!
android android-testing android-instrumentation android-uiautomator
我正在使用 Espresso 来测试 ViewHolder 中带有 RecyclerView 和 ComposeView 的屏幕。我想单击 RecyclerView 中的特定可组合项, 谢谢
android android-testing android-espresso android-recyclerview android-jetpack-compose
我请求对这个问题的一些帮助。我编写本教程是为了通过最新的“使用 Kotlin 开发 Android 应用程序”来刷新记忆并更新我的知识。
https://classroom.udacity.com/courses/ud9012
在第6课第10课上,有以下源代码: https: //github.com/udacity/andfun-kotlin-sleep-tracker/tree/Step.03-Solution-Create-RoomDatabase
@Test
@Throws(Exception::class)
fun insertAndGetNight() {
val night = SleepNight()
sleepDao.insert(night)
val tonight = sleepDao.getTonight()
assertEquals(tonight?.sleepQuality, -1)
}
Run Code Online (Sandbox Code Playgroud)
据说,它应该通过测试,但执行后,它返回:
Test Passed: 0 passed.
Run Code Online (Sandbox Code Playgroud)
在右侧的终端中我可以读到:
运行测试
$ adb shell am instrument -w -m -e debug false -e class 'com.example.android.trackmysleepquality.SleepDatabaseTest#insertAndGetNight' com.example.android.trackmysleepquality.test/android.test.InstrumentationTestRunner
"Run Android instrumented tests using Gradle" option was ignored because this module type is not supported yet.
Run Code Online (Sandbox Code Playgroud)
项目出了什么问题,为什么测试没有通过?
我加了一段文字手动写,结果是一样的,0测试通过。这是我添加的测试:
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
Run Code Online (Sandbox Code Playgroud)
另外,我尝试在测试设置(转到文件>>设置>>测试)中取消选中“使用 Gradle 运行 Android 仪器测试”旁边的框,结果相同。
我的 gradle 文件中有一个共享测试文件夹,配置如下:
androidTest {
java.srcDirs += "src/sharedTest/java"
}
test {
java.srcDirs += "src/sharedTest/java"
}
Run Code Online (Sandbox Code Playgroud)
但是,在启动时我从 Android Studio 收到此错误:
Duplicate content roots detected
Path [/Users/fil/Documents/projects/deploy/app/build/generated/source/r/debug] of module [deploy.app.unitTest] was removed from modules
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题有什么想法吗?我发现我可能会使用测试装置,但我还没有找到可以遵循的实用指南:(
我有一个非常奇怪的问题,我一整天都被困在这个问题上。
\n我的 CI/CD 每天会自动将最新版本从主分支上传到 Google Play Console 中的内部测试轨道几次。
\n如下图所示,内部测试轨道中的最新版本已经发布了几个小时,并且它表示 \xe2\x80\x99s \xe2\x80\x9cavailable 可供内部测试人员使用\xe2\x80\x9d。
\n\n然而,我\xe2\x80\x99ve注意到测试人员实际上并没有\xe2\x80\x99t获得更新版本,当我打开测试人员邀请链接并在浏览器中的Google Play中检查内部测试应用程序时,它显示更新于八月2022 年 8 月。
\n\n这与 Google Play 管理中心的发布历史记录中的内容相匹配。
\n\n此外,当我通过内部测试在我的设备上安装该应用程序时,它显示21.07.2022。
\n\n8 月 8 日左右,我激活了托管发布,因此我认为这可能是问题所在,但根据文档,托管发布根本不应该影响内部测试。该应用程序尚未在生产环境中发布,但在 8 月 8 日,我确实将一个版本推广到生产环境并通过了审核,但由于我已打开管理发布功能,因此尚无法供用户使用。
\n我在 SO 和其他地方读过大量类似的问题,但我还没有找到解决我的问题的方法。我\xe2\x80\x99m 不确定可能出了什么问题。我\xe2\x80\x99ve 遇到了通常的困难,内部测试版本交付给测试人员很慢,必须清除缓存等,但这对我来说是全新的。
\n当转到 Google Play 管理中心的起始页并按“所有应用程序”时,该应用程序的信息如下:
\n应用状态:已结束测试\n更新状态:准备发布
\n\n也许这暗示出了什么问题?也许这与由于托管发布而未发布的封闭测试轨道有关?
\n为什么测试人员无法使用 Google Play Console 中的最新内部测试版本?
\n我非常感谢任何帮助。
\nandroid android-testing google-play-console google-play-internal-testing
android ×10
android-testing ×10
google-mlkit ×1
google-play-internal-testing ×1
javascript ×1
kotlin ×1
testing ×1