Set custom path on JUnit report?

android

(MiraiCoder) #1

Hi,

I am trying to set a custom path on the JUnit report. I am using Android and the default paths are build/reports/tests/testDebugUnitTest and build/reports/tests/testReleaseUnitTest

Any help would really be appreciated!


(René Groeschke) #2

you should be able to configure the html and xml output explicitly per task. In the following example I apply a custom directory for each task of type test and use the task name to build up the report path:

test {
    reports.junitXml.destination = file("$buildDir/xml")
    reports.html.destination = file("$buildDir/html")
}

(MiraiCoder) #3

Thanks a lot! Where exactly I put this in my gradle file please?


(René Groeschke) #4

it shouldn’t matter where in your build file you put this snippet


(MiraiCoder) #5

Thanks a lot for the help! I am the same guy who asked the SO question…!

I am a beginner in this and I can’t get it to work…

In my android project I have 2 gradle files.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.app.id"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.0'
    testCompile 'junit:junit:4.12'
}

Can you please tell me where in these files I should add this please?

Thanks a ton for the help! I am really thankful!

I am running the build with the command gradlew clean testReleaseUnitTest


(René Groeschke) #6

as mentioned, you should be fine just putting the snippet at the bottom of your build script of the android build script. otherwise to be safe you could also put it into the allprojects section of the root build.gradle file