sbabcoc / JUnit-Foundation

JUnit Foundation is a lightweight collection of JUnit watchers, interfaces, and static utility classes that supplement and augment the functionality provided by the JUnit API.
Apache License 2.0
22 stars 6 forks source link

Cannot get property 'absolutePath' on null object #94

Closed gorru closed 3 years ago

gorru commented 3 years ago

Hello. I'm trying to use JUnit-Foundation on an Android gradle project. I follow your setup and added the

testOptions {
        unitTests.all {
            jvmArgs "-javaagent:${classpath.find { it.name.contains('junit-foundation') }.absolutePath}"
        }
    }

section but when I try to synchronize gradle (or run a build) I get alway the Cannot get property 'absolutePath' on null object error. Any advice? Here my (partial) build.gradle

android {
    compileSdkVersion 28

    compileOptions {
        incremental true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.inpeco.protube.mobile"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 1
        versionName "2.2.0"
    }
}    
dependencies {
    testImplementation 'net.bytebuddy:byte-buddy:1.10.14' // I should add this due to classNotFoundExceptions
    testImplementation 'com.nordstrom.tools:junit-foundation:13.0.0'

    ...
}
sbabcoc commented 3 years ago

Hi, @gorru,

You shouldn't need to add the dependency for Byte Buddy. This is declared by JUnit Foundation itself and should therefore be automatically included as a transitive dependency.

I'm using Android Studio 4.1.1 in a simple project to test the ability to use JUnit Foundation in an Android project. The one thing to be aware of is that a basic Android project includes a top-level build file and sub-projects. I had to include the JUnit Foundation elements in the sub-project build script. Putting these elements in the top-level build file didn't work.

gorru commented 3 years ago

Could you please share your test project? Mine project also contains a sub project and there I configured Junit-foundation without success.

gorru commented 3 years ago

I retested Junit-foundation integrating it in a project I took from github. It obviously works even changing it to be more similar to mine (using androidx and other dependencies). No problems regarding netbuddy dependency nor "-javaagent:${classpath.find { it.name.contains('junit-foundation') }.absolutePath}" error. I peraphs noticed that it stops to work adding useJUnitPlatform() Is junit 5 supported by junit-foundation ?

sbabcoc commented 3 years ago

@gorru No, this library is specifically designed to work with JUnit 4. Which specific feature(s) of JUnit Foundation were you hoping to employ in your project?

sbabcoc commented 3 years ago

Since this issue appears related to an attempt to use JUnit Foundation with JUnit 5, I'm closing it.