提交 ca0b8bcd 创建 作者: Greyson Parrelli's avatar Greyson Parrelli

Added functional tests.

上级 f851e7e2
...@@ -17,14 +17,14 @@ before_script: ...@@ -17,14 +17,14 @@ before_script:
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- export ANDROID_HOME=$PWD/android-sdk-linux - export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew - chmod +x ./gradlew
stages: stages:
- build
- test - test
build: build:
stage: build stage: test
script: script:
- ./gradlew assembleDebug - ./gradlew assembleDebug
artifacts: artifacts:
...@@ -35,3 +35,15 @@ unitTests: ...@@ -35,3 +35,15 @@ unitTests:
stage: test stage: test
script: script:
- ./gradlew test - ./gradlew test
functionalTests:
stage: test
script:
- wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/0f497eb71291b52a703143c5cd63a217c8766dc9/community-cookbooks/android-sdk/files/default/android-wait-for-emulator
- chmod +x android-wait-for-emulator
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter sys-img-x86-google_apis-${ANDROID_TARGET_SDK}
- echo no | android-sdk-linux/tools/android create avd -n test -t android-${ANDROID_TARGET_SDK} --abi google_apis/x86
- android-sdk-linux/tools/emulator64-x86 -avd test -no-window -no-audio &
- ./android-wait-for-emulator
- adb shell input keyevent 82
- ./gradlew cAT
\ No newline at end of file
...@@ -26,4 +26,5 @@ dependencies { ...@@ -26,4 +26,5 @@ dependencies {
}) })
compile 'com.android.support:appcompat-v7:25.0.0' compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
} }
...@@ -21,11 +21,16 @@ import static android.support.test.espresso.matcher.ViewMatchers.withText; ...@@ -21,11 +21,16 @@ import static android.support.test.espresso.matcher.ViewMatchers.withText;
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class AddingTest { public class AddingTest extends TestBase {
@Rule @Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class); public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);
@Override
ActivityTestRule getActivityRule() {
return mActivityRule;
}
@Test @Test
public void addNumbers() throws Exception { public void addNumbers() throws Exception {
// Enter numbers to be added // Enter numbers to be added
......
package com.greysonparrelli.gitlabciandroid;
import android.app.Activity;
import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.uiautomator.UiDevice;
import android.view.WindowManager;
import org.junit.Before;
/**
* Serves as a base test that will make sure that the screen is unlocked.
*
* @author Greyson Parrelli (keybase.io/greyson)
*/
public abstract class TestBase {
@Before
public void setup() {
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
try {
device.wakeUp();
} catch (RemoteException e) {
e.printStackTrace();
}
final Activity activity = getActivityRule().getActivity();
Runnable wakeUpDevice = new Runnable() {
public void run() {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
};
activity.runOnUiThread(wakeUpDevice);
}
abstract ActivityTestRule getActivityRule();
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论