一年后回到 Android 开发,我又对浓缩咖啡感到困惑-_-
我只是想设置一个简单的浓缩咖啡测试,但它失败了:
java.lang.RuntimeException:未找到活动。您是否忘记通过调用 getActivity() 或 startActivitySync 或类似方法启动活动?
事实上,我没有看到正在启动的应用程序。这是代码:
@RunWith(AndroidJUnit4::class)
@LargeTest
class EfficioTest {
@get:Rule @JvmField var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
private fun getActivity() = activityRule.activity
@Test fun testInitState() {
onView(withId(R.id.store_spinner)).check(matches(isDisplayed()))
}
}
Run Code Online (Sandbox Code Playgroud)
MainActivity 位于清单中,并且在使用启动器启动时工作正常。
我错过了什么?
我正在使用 Espresso 为我的 Android 应用程序编写 UI 测试,并想使用 MockWebServer 模拟 http 请求。在运行测试之前,我需要模拟身份验证响应并登录用户。
有没有办法让应用程序使用 mockwebserver,这样就不用发出实际请求,我可以使用在 mockwebserver 上排队的响应。
到目前为止,我有:
public class AuthenticationTest {
@Rule
public ActivityTestRule<Authentication> mActivityTestRule = new ActivityTestRule<>(Authentication.class);
private Authentication activity;
private MockWebServer server;
@Before
public void signin() throws Exception {
server = new MockWebServer();
server.start();
activity = mActivityTestRule.getActivity();
MyApplication.State state = activity.getState();
String serverUrl = server.url("/").toString();
// Here is where I have a problem. How to force client to use mock server?
}
@Test
public void firstTest() {
String contentType …Run Code Online (Sandbox Code Playgroud) 我看到 Android 在输出文件夹中创建了一个“正常”和一个 androidTest APK?
IE
例如,如果我想通过调试桥在设备上运行测试,是否需要安装这两个?
谢谢
我有一个由多个 gradle 模块组成的应用程序:
App -- main app module with dependencies to all submodules
|
|-- API - library module
| |-- Constants for authority etc.
|
|-- DB-Impl - library module
| |-- ContentProvider for the data specified in API
|
|-- Extension - library module
| |-- Dependency on API and test-dependency on DB-Impl
Run Code Online (Sandbox Code Playgroud)
这在构建和部署主 apk 时工作正常。所有模块都在清单中使用相同的 sharedUserId,并且可以从 DB-Impl 访问提供程序。
然而,当我尝试为不同的模块运行仪器测试时,它变得复杂了。
例如:我运行 DB-Impl 测试,该模块单独安装在设备上。当我想部署主应用程序或尝试运行它的测试时,apk 安装失败,因为它还包含提供程序,引发INSTALL_FAILED_CONFLICTING_PROVIDER错误。
扩展模块也是如此。它需要数据库,通常包含在主应用程序 apk 中。当简单地运行测试时,它们会因为没有安装提供程序而失败。所以我添加了androidTestCompile对 DB-Impl 模块的依赖。现在这个测试 apk 还包括提供者定义,导致更多的错误。
我尝试在测试任务上添加任务依赖项,因此它会运行uninstallAll,但是这只会卸载从中调用它的模块,因此我必须手动卸载可能随提供程序一起提供的每个模块。 …
android android-contentprovider android-testing android-gradle-plugin
我现在是一名实习生,刚接触自动化测试。我的目标是帮助我的公司为客户端设置 CI。
现在我有一个 maven 项目,其中包含几个使用 Appium java-client lib 的测试,在 Eclipse IDE 下,它可以在本地运行 UI 测试。我下一步的目标是将我的测试与 gitlab 存储库(已经存在,由 android 开发人员创建)挂钩,但我被困在这里。有人可以帮我吗?请尽量具体:
提前谢谢了!
有没有办法在启用了Android Test Orchestrator 的情况下从 Android Studio 在 Firebase 测试实验室中运行仪器测试?
在我的build.gradle 我有所有必需的陈述:
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
}
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
}
}
dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestUtil 'com.android.support.test:orchestrator:1.0.2'
}
Run Code Online (Sandbox Code Playgroud)
当我在自己的物理设备上运行测试时,Orchestrator 正在运行。
我能够在 Android Studio 中创建运行/调试配置以在 Firebase 测试实验室中运行测试,并且它们运行成功,但没有 Orchestrator。是否有一个选项可以在 Android Studio 中启用 Orchestrator,以便它也可以在 Firebase 运行中运行?
android android-testing firebase android-studio firebase-test-lab
我在我的项目中使用了 AndroidJUnitRunner,但是单元测试在 Android Studio 和命令行中通过gradlew.
我正在使用这个开源项目的主分支 OneBusAway(截至本次提交):https : //github.com/OneBusAway/onebusaway-android
我看到所有 142 个测试的执行时间在实际运行时间中超过 3 分钟,但 Android 在它显示在“测试结果”下的执行时间中只注册了其中的一小部分。在切换到 AndroidJUnitRunner 之前,所有这些单元测试都在 20 秒内一致地执行。
下面是一个示例测试:
/**
* Tests to evaluate utility methods related to math conversions
*/
@RunWith(AndroidJUnit4.class)
public class MathUtilTest {
@Test
public void testOrientationToDirection() {
// East
double direction = MathUtils.toDirection(0);
assertEquals(90.0, direction);
}
}
Run Code Online (Sandbox Code Playgroud)
这是build.gradle配置:
android {
dexOptions {
preDexLibraries true
}
compileSdkVersion this.ext.compileSdkVersion
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 93 …Run Code Online (Sandbox Code Playgroud) android android-testing android-studio android-gradle-plugin android-junit
我正在向应用程序添加仪器测试。我想测试围绕语音识别的交互:
R.id.buttonVoice),显示DialogFragment用于语音识别的 SpeechRecognizer踢入,聆听用户输入 TextView( R.id.results)使用Espresso-Intents 进行仪器测试听起来是确保我的测试不依赖于系统的SpeechRecognizer.
这是我的测试,它与intended()存根意图进行相同的交互:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityWithPermissionTest {
@Rule
public IntentsTestRule intentsTestRule = new IntentsTestRule<>(MainActivity.class);
@Test
public void clickInput_sendsSpeakIntentAndDisplaysResults() {
// stub intent returning recognition results
intending(hasAction(equalTo(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)))
.respondWith(new ActivityResult(Activity.RESULT_OK, new Intent().putExtra(
SpeechRecognizer.RESULTS_RECOGNITION, new String[]{"I am uttering."})));
// when clicking on the buttonVoice, thus opening the dialog and starting the speechRecognizer
onView(withId(R.id.buttonVoice))
.perform(click());
// expect the recognition …Run Code Online (Sandbox Code Playgroud) android speech-recognition android-intent android-testing android-espresso
我正在使用 Espresso 进行自动化测试。
可以写入 Instrumentation 测试类的文件夹丢失
我尝试添加
android{
sourceSets{
main { java.srcDirs = ['src/main/java'] }
test { java.srcDirs = ['src/test/java'] }
androidTest { java.srcDirs = ['src/androidTest/java'] }
}
}
Run Code Online (Sandbox Code Playgroud)
在build.gradle里面,但没有用。
尝试使用此问题中提供的其他解决方案生成仍然不起作用
我正在尝试单独测试 a Fragment。为此,我正在尝试FragmentScenario.
Android 文档在这里提供了一个非常好的示例。但是我的测试总是失败,因为我的片段将活动投射到onAttach.
FragmentScenarioluanches 一个容器Activity(显然)没有实现我的片段所需的接口。
我的问题是如何解决这个问题?如何强制容器活动实现我需要的接口?或者有没有更好的方法来做到这一点?也许移除铸件onAttach并用不同的方法替换?