Compare commits

...

8 Commits

Author SHA1 Message Date
Jonas Kalderstam 603d296f5b remember command for permission granting 2015-08-22 15:50:30 +02:00
Jonas Kalderstam 91f07b9a61 Add script to run CI 2015-08-21 13:34:14 +02:00
Jonas Kalderstam 8a85e5b27a build file for jenkins 2015-08-21 12:55:57 +02:00
Jonas Kalderstam e86ebcf969 Some stubs 2015-08-21 02:18:52 +02:00
Jonas Kalderstam bd08039fd1 first uiautomator test 2015-08-21 02:13:04 +02:00
Jonas Kalderstam f460571e7c UiAutomator 2015-08-21 02:01:29 +02:00
Jonas Kalderstam ce61dbb65b Simple travis config 2015-08-21 01:16:46 +02:00
Jonas Kalderstam ad6d494f14 simple test implemented 2015-08-21 01:03:55 +02:00
7 changed files with 320 additions and 3 deletions

4
.ci Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
## Install package and grant all permissions
adb install -r -g sample/build/outputs/apk/sample-debug.apk

3
.cloudbees.md Normal file
View File

@ -0,0 +1,3 @@
# Build
./gradlew clean build check

View File

@ -20,8 +20,17 @@ cache:
before_install:
- chmod +x gradlew
# - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
# - emulator -avd test -no-skin -no-audio -no-window &
#before_script:
# # Make sure emulator has started before running tests
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- ./gradlew clean build check
- ./gradlew clean build connectedCheck
# connectedCheck
# - ./gradlew assembleDebug
# - ./gradlew connectedAndroidTestDebug --info

View File

@ -26,6 +26,9 @@ android {
targetSdkVersion 23
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
//testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@ -37,6 +40,11 @@ android {
}
}
}
// Conflict in test project
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
@ -45,4 +53,16 @@ dependencies {
// Image loading sample
compile 'com.github.bumptech.glide:glide:3.5.2'
// For running tests
androidTestCompile ('com.android.support.test:runner:0.3') {
exclude module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude module: 'support-annotations'
}
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015 Jonas Kalderstam
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Lesser General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<manifest
xmlns:tools="http://schemas.android.com/tools"
package="com.nononsenseapps.filepicker.sample">
<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
</manifest>

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 2015 Jonas Kalderstam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nononsenseapps.filepicker.sample;
import android.os.Environment;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.action.ViewActions;
import android.test.ActivityInstrumentationTestCase2;
import android.test.ViewAsserts;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.View;
import java.io.File;
import java.io.IOException;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
public class NoNonsenseFilePickerTest extends ActivityInstrumentationTestCase2<NoNonsenseFilePicker> {
private NoNonsenseFilePicker mActivity;
private View mStartButton;
private static final String[] sTestFiles = new String[] {"zz.testfile1.zxvf", "zz.testfile2.zxvf"};
public NoNonsenseFilePickerTest() {
super(NoNonsenseFilePicker.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
setActivityInitialTouchMode(true);
mActivity = getActivity();
mStartButton = mActivity.findViewById(R.id.button_sd);
// Create a few files so we know something exists
createTestFiles();
}
private void createTestFiles() throws IOException {
String folder = Environment.getExternalStorageDirectory().getPath();
for (String filename: sTestFiles) {
File file = new File(folder + "/" + filename);
if (!file.exists()) {
assertTrue(file.createNewFile());
}
}
}
/**
* Load app, and make sure it loaded
*/
@MediumTest
public void testStart() {
final View mainView = mActivity.findViewById(R.id.scrollView);
assertNotNull(mainView);
final View radioButtons = mActivity.findViewById(R.id.radioGroup);
assertNotNull(radioButtons);
ViewAsserts.assertOnScreen(mainView, radioButtons);
ViewAsserts.assertOnScreen(mainView, mStartButton);
}
/**
* Start picker with default options
*/
@MediumTest
public void testNoSelectionOnOk() {
getActivity();
onView(withId(R.id.button_sd)).perform(ViewActions.click());
// Activity should now be started
// Verify that OK-button is present
//onView(withId(R.id.nnf_button_ok)).check(ViewAssertions.matches(withText(android.R.string.ok)));
// Press it
onView(withId(R.id.nnf_button_ok)).perform(ViewActions.click());
// Should have given a toast, asking to select something first
// Press cancel to go back
onView(withId(R.id.nnf_button_cancel)).perform(ViewActions.click());
}
@MediumTest
public void testSelectOne() {
getActivity();
onView(withId(R.id.button_sd)).perform(ViewActions.click());
// Select a file
// Activity should now be started
// Verify that OK-button is present
//onView(withId(R.id.nnf_button_ok)).check(ViewAssertions.matches(withText(android.R.string.ok)));
// Press it
onView(withId(R.id.nnf_button_ok)).perform(ViewActions.click());
}
}

View File

@ -0,0 +1,140 @@
/*
* Copyright (c) 2015 Jonas Kalderstam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nononsenseapps.filepicker.sample;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.test.InstrumentationTestCase;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.By;
import android.test.suitebuilder.annotation.MediumTest;
import java.io.File;
import java.io.IOException;
public class UITest extends InstrumentationTestCase {
public static final String PKG_SAMPLE = "com.nononsenseapps.filepicker.sample";
private static final long TIMEOUT = 10;
private UiDevice mDevice;
private static final String[] sTestFiles = new String[] {"zz.testfile1.zxvf", "zz.testfile2.zxvf"};
public void setUp() throws IOException {
// Initialize UiDevice instance
mDevice = UiDevice.getInstance(getInstrumentation());
// Launch sample app
Context context = getInstrumentation().getContext();
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(PKG_SAMPLE);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Clear out any previous instances
context.startActivity(intent);
mDevice.wait(Until.hasObject(By.pkg(PKG_SAMPLE).depth(0)), TIMEOUT);
// Create a few files so we know something exists
createTestFiles();
}
private void createTestFiles() throws IOException {
String folder = Environment.getExternalStorageDirectory().getPath();
for (String filename: sTestFiles) {
File file = new File(folder + "/" + filename);
if (!file.exists()) {
assertTrue(file.createNewFile());
}
}
}
@MediumTest
public void testSelectSingleFile() throws Exception {
// Default options are correct, press start
UiObject sdButton = mDevice.findObject(new UiSelector().resourceId("com.nononsenseapps.filepicker.sample:id/button_sd"));
assertTrue(sdButton.exists());
sdButton.click();
// Scroll to bottom and click on a test file
UiScrollable list = new UiScrollable(new UiSelector()
.className("android.support.v7.widget.RecyclerView"));
UiObject testFileItem2 = list.getChildByText(new UiSelector()
.resourceId("com.nononsenseapps.filepicker.sample:id/nnf_item_container"),
sTestFiles[1]);
testFileItem2.click();
// Click another one, only one should be returned
UiObject testFileItem1 = list.getChildByText(new UiSelector()
.resourceId("com.nononsenseapps.filepicker.sample:id/nnf_item_container"),
sTestFiles[0]);
testFileItem1.click();
// Press oK
UiObject okButton = mDevice.findObject(new UiSelector().resourceId("com.nononsenseapps.filepicker.sample:id/nnf_button_ok"));
okButton.click();
// Make sure result is displayed correctly
UiObject resultField = mDevice.findObject(new UiSelector().textContains(sTestFiles[0]));
assertTrue(resultField.exists());
resultField = mDevice.findObject(new UiSelector().textContains(sTestFiles[1]));
assertFalse(resultField.exists());
}
@MediumTest
public void testSelectMultipleFiles() throws Exception {
throw new UnsupportedOperationException("Not implemented yet");
}
@MediumTest
public void testSelectSingleDir() throws Exception {
throw new UnsupportedOperationException("Not implemented yet");
}
@MediumTest
public void testSelectMultipleDirs() throws Exception {
throw new UnsupportedOperationException("Not implemented yet");
}
@MediumTest
public void testSelectMultipleAny() throws Exception {
throw new UnsupportedOperationException("Not implemented yet");
}
@MediumTest
public void testCreateDirModeFile() throws Exception {
throw new UnsupportedOperationException("Not implemented yet");
}
@MediumTest
public void testCreateDirModeDir() throws Exception {
throw new UnsupportedOperationException("Not implemented yet");
}
@MediumTest
public void testCreateDirModeAny() throws Exception {
throw new UnsupportedOperationException("Not implemented yet");
}
}