Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46c72cd5 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Merge branch 'instrumentation-test-oreo' into 'v1-oreo'

Instrumentation test oreo

See merge request e/apps/eDrive!44
parents f3b3935e 9503b6cf
Loading
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
image: "registry.gitlab.e.foundation:5000/e/apps/docker-android-apps-cicd:latest"

stages:
- test
- build

before_script:
@@ -9,15 +10,32 @@ before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- chmod +x ./gradlew


cache:
  key: ${CI_PROJECT_ID}
  paths:
  - .gradle/


test:
  allow_failure: true
  stage: test
  script:
    - ls /usr/lib/jvm/
    - ./gradlew test -Dorg.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64 -PtestAccountName="$testAccountName" -PtestAccountPwd="$testAccountPwd" -PtestServerUrl="$testServerUrl"
  artifacts:
    when: always
    paths:
      - app/build/test-results/*/TEST-*.xml
      - app/build/reports/tests/*
    reports:
      junit: app/build/test-results/*/TEST-*.xml


build:
  stage: build
  script:
  - ./gradlew build
  - ./gradlew build -x test
  artifacts:
    paths:
    - app/build/outputs/apk/

.idea/modules.xml

deleted100644 → 0
+0 −11
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/Drive.iml" filepath="$PROJECT_DIR$/Drive.iml" />
      <module fileurl="file://$PROJECT_DIR$/nextcloud-android-lib/NextcloudLib.iml" filepath="$PROJECT_DIR$/nextcloud-android-lib/NextcloudLib.iml" />
      <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
      <module fileurl="file://$PROJECT_DIR$/eDrive.iml" filepath="$PROJECT_DIR$/eDrive.iml" />
    </modules>
  </component>
</project>
 No newline at end of file
+35 −3
Original line number Diff line number Diff line
@@ -9,6 +9,18 @@ def buildTime() {
    return df.format(new Date())
}

def getTestProp(String propName) {
    def result = ""
    if(project.hasProperty(propName)){
        result =project.property(propName).toString()
    }else if(project.rootProject.file('local.properties').exists()){
        Properties properties = new Properties()
        properties.load(project.rootProject.file('local.properties').newReader())
        result = properties.getProperty(propName)
    }
    return result
}


android {
    compileSdkVersion 26
@@ -19,7 +31,9 @@ android {
        //versionName "1.0"
        versionName "beta-${versionMajor}-build-o-${buildTime()}"
        setProperty("archivesBaseName", "$applicationId.$versionName")

        buildConfigField "String", "testAccountName", "\""+getTestProp("testAccountName")+"\""
        buildConfigField "String", "testAccountPWd", "\""+getTestProp("testAccountPwd")+"\""
        buildConfigField "String", "testServerUrl", "\""+getTestProp("testServerUrl")+"\""
    }
    buildTypes {
        release {
@@ -34,19 +48,37 @@ android {


    testOptions {
        unitTests.returnDefaultValues = true
        unitTests {
            returnDefaultValues = true
            //includeAndroidResources = true
        }
    }

}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'com.android.support:support-annotations:27.1.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    api 'com.android.support:support-annotations:27.1.1'
    api project(':NextcloudLib')

    //start to add lib for test - 1/4/21
    //@TODO: add junit runner as lib for testImplementation

    testImplementation 'com.android.support.test:runner:1.0.2'
    testImplementation 'com.android.support.test:rules:1.0.2'
    testImplementation 'junit:junit:4.12'
    //testImplementation 'org.robolectric:robolectric:4.4' //need AndroidX
    testImplementation "org.robolectric:robolectric:3.8"
    testImplementation('org.mockito:mockito-inline:3.4.0')

    //testImplementation Libs.AndroidX.Test.archCoreTesting //TODO: replace by not android X version
    //implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
    androidTestImplementation  'junit:junit:4.12'
}
+0 −36
Original line number Diff line number Diff line
/*
 * Copyright © Vincent Bourgmayer (/e/ foundation).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 */


package foundation.e.drive;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * 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();


        assertEquals("foundation.e.drive", appContext.getPackageName());
    }
}
+100 −0
Original line number Diff line number Diff line
package foundation.e.drive.services;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ServiceTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.TimeoutException;

import static android.support.test.InstrumentationRegistry.getContext;
import static org.junit.Assert.*;




/**
 * 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 ObserverServiceInstrumentedTest {
    private final static String NEW_SMALL_FILE_PATH = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DOCUMENTS+File.separator+"test-small-file.txt";
    private final static String ACCOUNT_NAME= "";
    private final static String ACCOUNT_PASS="";
    private final static String ACCOUNT_TYPE="";


    @Rule
    public final ServiceTestRule mServiceRule = new ServiceTestRule();


    @Before
    public void RegisterAccount() throws Exception {
        final Account account = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
        AccountManager.get(getContext()).addAccountExplicitly(account, ACCOUNT_PASS, null);

    }


    /**
     * Souldn't it be more for a unit test ?
     * @throws IOException
     */
    @Before
    public void createLocalSmallFile() throws IOException {

        File file = new File(NEW_SMALL_FILE_PATH);
        file.createNewFile();
        String content = "this a very small content";
//write the bytes in file
        if(file.exists())
        {
            OutputStream fo = new FileOutputStream(file);
            fo.write(content.getBytes());
            fo.close();
            System.out.println("file created: "+file);
        }
    }


    @After
    public void deleteLocalSmallFile(){
        File file = new File(NEW_SMALL_FILE_PATH);
        //deleting the file
        file.delete();
    }


    @Test
    public void testWithStartedService() throws TimeoutException {
        mServiceRule.startService(
                new Intent(InstrumentationRegistry.getTargetContext(), ObserverService.class));
        //do something
    }

    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();


        assertEquals("foundation.e.drive", appContext.getPackageName());
    }
}
Loading