Skip to content

Commit

Permalink
Merge hotfixes for travis build and coverage
Browse files Browse the repository at this point in the history
Hotfixes 0.1.1
  • Loading branch information
vbouquet authored Mar 2, 2017
2 parents 32d556b + e5fd28d commit 1ec97f7
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 47 deletions.
24 changes: 7 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
language: android
jdk: oraclejdk8
# Use the Travis Container-Based Infrastructure
sudo: false
sudo: required

env:
global:
# - ANDROID_TARGET=android-22
# - ANDROID_ABI=armeabi-v7a
- ANDROID_API_LEVEL=23
- EMULATOR_API_LEVEL=21
- ANDROID_BUILD_TOOLS_VERSION=23.0.2
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)
- ANDROID_TRAVIS=1
android:
components:
- tools
Expand All @@ -21,28 +17,22 @@ android:
# Specify both versions to resolve issue with missing image from google repository
- android-$ANDROID_API_LEVEL
- android-$EMULATOR_API_LEVEL
- build-tools-23.0.2
- extra-android-support
- extra-android-m2repository
- extra-android-google_play_services
- extra-google-m2repository
- extra-android-support
# Image 23 might be missing from google repository
- sys-img-armeabi-v7a-google_apis-$ANDROID_API_LEVEL
- sys-img-armeabi-v7a-google_apis-$EMULATOR_API_LEVEL
licenses:
- 'android-sdk-preview-license-.+'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'

# Launch android emulator and wait for it
before_script:
- echo no | android create avd --force -n test -t "android-"$EMULATOR_API_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- echo no | android create avd --force -n test -t "android-"$EMULATOR_API_LEVEL --abi $ANDROID_ABI #--tag $ANDROID_TAG
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &

script:
- ./gradlew connectedAndroidTest coveralls
- ./gradlew jacocoTestReport coveralls

notifications:
email: false

slack: assogenda:m88NLRiY4UxkgThbI1ONxdFr
37 changes: 32 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.57-beta'
testCompile 'org.robolectric:robolectric:3.2.2'

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
Expand All @@ -51,17 +58,37 @@ dependencies {
compile 'com.firebaseui:firebase-ui-storage:0.6.0'
}

// Enable coverage for AndroidTests and UnitTests
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

reports {
xml.enabled = true
html.enabled = true
}

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"

sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/code-coverage/connected/*coverage.ec"
])
}

sonarqube {
properties {
property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
property "sonar.jacoco.reportPath", "${buildDir}/jacoco/test.exec"
}
}

coveralls {
jacocoReportPath = "${buildDir}/reports/coverage/debug/report.xml"
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
}

tasks.coveralls {
dependsOn 'connectedAndroidTest'
dependsOn 'jacocoTestReport'
onlyIf { System.env.'CI' }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fr.paris10.projet.assogenda.assogenda.ui.activites;

import android.widget.Button;

import com.google.firebase.FirebaseApp;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import fr.paris10.projet.assogenda.assogenda.BuildConfig;
import fr.paris10.projet.assogenda.assogenda.R;

import static org.junit.Assert.*;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 22)

public class AssociationDashboardRoboTest {
private AssociationDashboardActivity activity;

@Before
public void setUp() throws Exception {
FirebaseApp.initializeApp(RuntimeEnvironment.application.getApplicationContext());
activity = Robolectric.buildActivity(AssociationDashboardActivity.class).create().get();
}

@Test
public void shouldNotBeNull() throws Exception {
assertNotNull(activity);
}

@Test
public void shouldHaveMainFragment() throws Exception {
assertNotNull(activity.getFragmentManager()
.findFragmentById(R.id.activity_association_dashboard_fragment_container));
}

@Test
public void onCreateAsso() throws Exception {
Button button = (Button) activity.findViewById(R.id.fragment_association_main_button_create_association);
assertNotNull(button);
assertTrue(button.performClick());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package fr.paris10.projet.assogenda.assogenda.ui.activites;

import android.widget.Button;
import android.widget.TextView;

import com.google.firebase.FirebaseApp;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import fr.paris10.projet.assogenda.assogenda.BuildConfig;
import fr.paris10.projet.assogenda.assogenda.R;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.robolectric.Shadows.shadowOf;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk=22)

public class LoginActivityRoboTest {
private LoginActivity activity;
private final String textEmail = "[email protected]";
private final String textPwd = "strongpassword";

@Before
public void setUp() throws Exception {
FirebaseApp.initializeApp(RuntimeEnvironment.application.getApplicationContext());
activity = Robolectric.buildActivity(LoginActivity.class).create().get();
}

@Test
public void shouldNotBeNull() throws Exception {
assertNotNull(activity);
}

@Test
public void fillFields() throws Exception {
TextView email = (TextView) activity.findViewById(R.id.login_email);
TextView password = (TextView) activity.findViewById(R.id.login_password);
assertNotNull(email);
assertNotNull(password);
email.setText(textEmail);
password.setText(textPwd);
assertEquals(email.getText().toString(), textEmail);
assertEquals(password.getText().toString(), textPwd);
}

@Test
public void shouldNotSignedIn() throws Exception {
activity.signIn(textEmail, textPwd);
assertEquals(null, shadowOf(activity).peekNextStartedActivity());
TextView email = (TextView) activity.findViewById(R.id.login_email);
TextView password = (TextView) activity.findViewById(R.id.login_password);
Button logInButton = (Button) activity.findViewById(R.id.login_validate);
assertNotNull(logInButton);
assertTrue(logInButton.performClick());
assertEquals(null, shadowOf(activity).peekNextStartedActivity());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package fr.paris10.projet.assogenda.assogenda.ui.activites;

import android.content.Intent;
import android.test.mock.MockContext;

import com.google.firebase.FirebaseApp;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import fr.paris10.projet.assogenda.assogenda.BuildConfig;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.robolectric.Shadows.shadowOf;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 22)

public class MainActivityRoboTest {
private MainActivity activity;

@Before
public void setUp() throws Exception {
FirebaseApp.initializeApp(RuntimeEnvironment.application.getApplicationContext());
activity = Robolectric.setupActivity(MainActivity.class);
}

@Test
public void shouldNotBeNull() throws Exception {
assertNotNull(activity);
}

@Test
public void startNewActivityIfNotLoggedIn() throws Exception {
activity.redirectIfNotLoggedIn();
Intent expectedIntent = shadowOf(activity).peekNextStartedActivity();
assertEquals(LoginActivity.class.getCanonicalName(),
expectedIntent.getComponent().getClassName());
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
version '0.1.0'
version '0.1.1'

buildscript {
repositories {
Expand Down

0 comments on commit 1ec97f7

Please sign in to comment.