我是 Android 开发的新手。我正在使用 UIAutomator 和 Android Studio 3.0 中的另一个应用程序创建一个黑盒测试。我想在 Google Firebase 测试实验室中运行它。我收到大量不知道如何处理的警告/错误。这是我的代码project/app/src/androidTest/java/com.firebaseapp.test_test.test/ExampleInstrumentedTest.java
:
//This code doesn't wait for elements to appear, doesnt do error handling/reporting, etc.
//Its just a proof of concept of running in firebase test lab, which it doesnt
package com.firebaseapp.test_test.test;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertEquals;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
UiDevice mDevice = UiDevice.getInstance(getInstrumentation()); //assign device
assertEquals("com.firebaseapp.test_test.test", appContext.getPackageName()); //idk, this was here by default
Intent intent = appContext.getPackageManager().getLaunchIntentForPackage("com.testapp.android"); //look for testapp
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); //if testapp is currently running, close it
appContext.startActivity(intent); //start testapp
mDevice.wait(Until.hasObject(By.pkg("com.testapp.android")), 30); //make sure testappstarted correctly
mDevice.findObject(new UiSelector().resourceId("com.testapp.android:id/log_in")).clickAndWaitForNewWindow(); //Click log in button
mDevice.findObject(new UiSelector().resourceId("com.testapp.android:id/login_user")).setText("username"); //fill in username
mDevice.findObject(new UiSelector().resourceId("com.testapp.android:id/pass")).setText("password"); //Fill in password
mDevice.findObject(new UiSelector().resourceId("com.testapp.android:id/next_btn")).clickAndWaitForNewWindow(); //Click sign in, wait
}
}
这是我的清单 XML project/app/src/main/AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.firebaseapp.root_registrar.rootregistrar">
<uses-sdk
tools:overrideLibrary="android.support.test.uiautomator.v18"/> //idk if this is the right version, just found it online
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" />
</manifest>
这是我的错误(不包括所有正常的日志/警告,这将超过这篇文章的限制:
我尝试单独构建仪器测试 APK。我尝试构建它以进行调试。我尝试构建它以供发布。我尝试用签名构建它。在测试实验室运行它之前,我会遇到各种错误,说测试 APK 没有有效的签名,或者测试 APK 不包含清单文件中指定的测试运行程序类。我真的只是对来自测试实验室的所有这些应用程序签名、清单文件和看似随机的错误感到困惑(尽管 ExampleInstrumentation.java 在 Nexus 5 Android 7.0 上的 Android Studio 中运行测试很好)
我想我的问题很广泛。我应该怎么做才能让这个黑盒测试 apk 在 Firebase 测试实验室中沿着我的 testapp 的 APK 作为仪器测试运行?