caipivara
9/17/2015 - 6:04 PM

Android - Test helper scripts. Check that I use buildType mock for tests.

Android - Test helper scripts. Check that I use buildType mock for tests.

#!/bin/bash
#
# Run spoon tests and open results on browser
#
# You can run it passing the absolute class name if you want to run
# just one test class.
#

echo "Running tests :D..."

if [ $# -eq 1 ] ; then
    ./gradlew clean spoonMockAndroidTest -P spoonClassName=$1
elif [ $# -eq 2 ] ; then
    ./gradlew clean spoonMockAndroidTest -P spoonClassName=$1 -P spoonMethodName=$2
else
    ./gradlew clean spoonMockAndroidTest
fi

if [ "$?" -eq "0" ]
then
    echo "Testing runed fine. B-)"
else
  echo "Something failed runing tests :O!"
fi

open -b com.google.Chrome app/build/spoon/mock/index.html
#!/bin/bash
#
# Run tests to get coverage report.
# 1. Check if buildType have `testCoverageEnabled true` before running and check 
# 2. Change create<build_type>CoverageReport command with the right buildType if it is not mock.
# 

echo "Running coverage report :D..."

./gradlew clean createMockCoverageReport

if [ "$?" -eq "0" ]
then
    echo "Testing run fine. B-)"
	open -b com.google.Chrome app/build/reports/coverage/mock/index.html
else
  echo "Something failed running tests :O!"
fi
apply plugin: 'jacoco'

project.afterEvaluate {
    def append = "append=true"
    def destFile = "destfile=$buildDir/outputs/code-coverage/connected/coverage.ec"
    testMockUnitTest.jvmArgs "-javaagent:$buildDir/intermediates/jacoco/jacocoagent.jar=$append,$destFile"

    createMockCoverageReport.dependsOn testMockUnitTest
}

android {
    
    defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testBuildType "mock"
    }

    buildTypes {
        mock {
            minifyEnabled true
            testCoverageEnabled true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-tests.pro'
        }
    }

    sourceSets { androidTest.setRoot('src/androidTest') }
}

dependencies {
    androidTestCompile 'com.android.support.test:runner:0.4'
    androidTestCompile 'com.android.support.test:rules:0.4'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.squareup.spoon:spoon-client:1.2.0'
}

// Testing photos This section is optional
spoon {
    debug = false
    noAnimations = true

    if (project.hasProperty('spoonClassName')) {
        className = project.spoonClassName

        if (project.hasProperty('spoonMethodName')) {
            methodName = project.spoonMethodName
        }
    }
}