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 change resolution strategy of dependency configuration ':app:compile' after it has been resolved. #73

Closed YuryPashkov closed 4 years ago

YuryPashkov commented 4 years ago

I've tried Gradle Configuration for JUnit Foundation in my android project and got such build issue

Cannot change resolution strategy of dependency configuration ':app:compile' after it has been resolved.

Steps to reproduce

sbabcoc commented 4 years ago

I'm not a Gradle expert, by any standard. The most likely source of this failure is the ext section that attempts to acquire a reference to the JUnit Foundation artifact itself. What happens if you disable this section and hard-code the JAR path in the jvmArgs statement?

sbabcoc commented 4 years ago

In a Maven project, the process of acquiring the path to the JUnit Foundation JAR is handled by the Maven dependency plugin. You can see this in the Maven example that precedes the Gradle example you pointed to. I found this post that may provide a different approach to the problem:

https://stackoverflow.com/questions/16636702/gradle-equivalent-of-maven-dependency-plugin

sbabcoc commented 4 years ago

Here's another potential formulation: https://github.com/bmuschko/gradle-cargo-plugin/issues/63

sbabcoc commented 4 years ago

I think I have a working formula for Android:

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

This is definitely successful in applying the transformations of the JUnit 4 classes by the JUnit Foundation agent.

15:03:53.111 [Test worker] DEBUG com.nordstrom.automation.junit.Run - runStarted: org.junit.runners.BlockJUnit4ClassRunner@7e43c975
15:03:53.487 [Test worker] WARN com.nordstrom.automation.junit.JUnitConfig - Unable to locate configuration at path 'junit.properties'
15:03:53.527 [Test worker] DEBUG com.nordstrom.automation.junit.CreateTest - testObjectCreated: com.example.myapplication.ExampleUnitTest@5d4e3318
15:03:53.533 [Test worker] DEBUG com.nordstrom.automation.junit.RunAnnouncer - testStarted: addition_isCorrect(com.example.myapplication.ExampleUnitTest)
15:03:53.544 [Test worker] DEBUG com.nordstrom.automation.junit.RunReflectiveCall - beforeInvocation: addition_isCorrect(com.example.myapplication.ExampleUnitTest)
15:03:53.544 [Test worker] DEBUG com.nordstrom.automation.junit.RunReflectiveCall - afterInvocation: addition_isCorrect(com.example.myapplication.ExampleUnitTest)
15:03:53.546 [Test worker] DEBUG com.nordstrom.automation.junit.RunAnnouncer - testFinished: addition_isCorrect(com.example.myapplication.ExampleUnitTest)
15:03:53.547 [Test worker] DEBUG com.nordstrom.automation.junit.Run - runFinished: org.junit.runners.BlockJUnit4ClassRunner@7e43c975