aprsdroid icon indicating copy to clipboard operation
aprsdroid copied to clipboard

Add a testing framework to APRSdroid

Open penguin359 opened this issue 5 years ago • 1 comments

My initial efforts at getting a testing framework added are hitting a few walls. Part of the issue is how to structure the code. The current recommended structure includes having a main, test, and androidTest folder directly under src/ and no files in that folder directly. The test/ folder is for local unit tests that can run on the development host and androidTest/ is for the tests that run on the device and manipulate the running app. I'd like to get some local unit tests that might just inject audio packets into the back-end and verify valid decodes on the other end without need the Android framework. It would also been good for testing known, broken formats from a Kenwood TNC or similar. androidTest/ would be good for testing those darn application crashes when a null callsign is passed into the MapLoader.

I tried adding my test first in src/androidTest/ However, having everything the main app directly under src/, it's pulling in that test into the main app so it fails to find the androidTestImplemation dependencies since they aren't included. If I make all the dependencies implementation, it does compile. I could move androidTest/ to the top-level in the mean time and figure out how to include that.

Also, all current documentation for Unit testing on Android seems to go through the AndroidX compatibility layer now. I'm using some older documentation that works with the older Android JUnit, but it might be better to go with the current recommended setup.

I'm also trying to understand the Scala plugin. It seems that it's in charge of compiling everything including Java files and then indirectly calls javac as needed so my Java JUnit tests go through it. It also grabs all files it sees including a .java2 and my Vim .swp files. This was an annoying error to deal with:

IO error while decoding /home/lorenl/aprsdroid/src/androidTest/java/org/aprsdroid/app/.ExampleInstrumentedTest.java.swp with UTF-8

I'd really like to figure out how to get Scala plugin to ignore .swp files.

penguin359 avatar Aug 30 '20 20:08 penguin359

My initial efforts to add androidTest/ from the top-level have failed. I tried adding this:

android {
    ...
    sourceSets {
        ...
        androidTest {
            scala.srcDirs = ['androidTest/java']
            java.srcDirs = ['androidTest/java'] 
        }
    }
}

But it doesn't seem to be reacting to that. In fact, it's not even complaining about the scala.srcDirs line like I would expect. Elsewhere, there is this:

// some gradle-android-scala-plugin versions don't know scala.* properties
// if it breaks, just remove the following two lines:
//scala.srcDirs = ['src']
//scala.excludes = ["*.sw?"]

Previously, those lines were un-commented, but I would get build errors like this:

No such property: excludes for class: jp.leafytree.gradle.AndroidScalaPluginExtension

I'm a little curious why you weren't getting those errors since it seems that a precise version of the gradle-android-scala-plugin is being selected. I'm also trying to figure out where it is finding the 3.5.1 release of the plug-in. It isn;'t going directly to Github is it? I checked the Maven Central and JCentral repos and I can only find the 1.4 release from 2015 by the original author of the plugin.

penguin359 avatar Aug 30 '20 21:08 penguin359