How to run unit/integration tests for a rosjava-android project?

asked 2020-01-22 15:38:53 -0600

Hey, I'm facing the problem of developing an app using ROS and not being able to write tests, both simple unit tests and integration tests.

The application should run on Android phones and tablets, connect to an external roscore over wireless networks and subscribe and publish to nodes. Therefore I worked my way through the tutorial on android_tutorial_kinetic and came up with this:

Project build.gradle

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

buildscript {
    apply from: "https://github.com/rosjava/android_core/raw/kinetic/buildscript.gradle"
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

subprojects {

    apply plugin: 'ros-android'

    afterEvaluate { project ->
        android {
            // Exclude a few files that are duplicated across our dependencies and
            // prevent packaging Android applications.
            packagingOptions {
                exclude "META-INF/LICENSE.txt"
                exclude "META-INF/NOTICE.txt"
            }
        }
    }
}

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

App module build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.2'

    defaultConfig {
        applicationId "com.xxx.testapplication"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

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

    // Tests
    testImplementation 'junit:junit:4.13'

    // Android
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'

    // Material
    implementation 'com.google.android.material:material:1.0.0'

    // ROS
    implementation "org.ros.rosjava_core:rosjava:0.3.6"
    implementation "org.ros.rosjava_messages:diagnostic_msgs:1.12.7"
    implementation 'org.ros.rosjava_messages:geometry_msgs:1.12.7'
    implementation 'org.ros.rosjava_messages:nav_msgs:1.12.7'
    implementation 'org.ros.rosjava_messages:std_msgs:0.5.11'
    implementation 'org.ros.rosjava_messages:sensor_msgs:1.12.7'
    implementation 'org.ros.rosjava_bootstrap:message_generation:0.3.3'
    implementation 'org.ros.android_core:android_core_components:0.4.0'
}

configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}

As you might guess, I develop under Android Studio and am bound to rosjava. So far so good, everything is running like clockwork, except that I have reached the point where I would like to write unit and integration tests.

But unfortunately the test build always fails with messages like this one:

error: package org.junit does not exist

when I try to use any org.junit imports, variables, functions or annotations.

Have any of you ever encountered this problem and is there a workaround to successfully import junit?
Thanks a lot for your help and I wish you a happy development.

Android Studio Version: 3.5.2
Gradle version: 3.5.3

edit retag flag offensive close merge delete