@ -25,7 +25,6 @@ import org.gradle.api.tasks.testing.TestFrameworkOptions;
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions ;
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions ;
import org.gradle.testretry.TestRetryPlugin ;
import org.gradle.testretry.TestRetryPlugin ;
import org.gradle.testretry.TestRetryTaskExtension ;
import org.gradle.testretry.TestRetryTaskExtension ;
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest ;
import java.util.Map ;
import java.util.Map ;
@ -36,7 +35,7 @@ import java.util.Map;
* < li > The { @link TestRetryPlugin Test Retry } plugin is applied so that flaky tests
* < li > The { @link TestRetryPlugin Test Retry } plugin is applied so that flaky tests
* are retried 3 times when running on the CI server .
* are retried 3 times when running on the CI server .
* < li > Common test properties are configured
* < li > Common test properties are configured
* < li > The Mockito Java agent is set on test tasks .
* < li > The ByteBuddy Java agent is configured on test tasks .
* < / ul >
* < / ul >
*
*
* @author Brian Clozel
* @author Brian Clozel
@ -50,7 +49,7 @@ class TestConventions {
}
}
private void configureTestConventions ( Project project ) {
private void configureTestConventions ( Project project ) {
configureMockito Agent ( project ) ;
configureByteBuddy Agent ( project ) ;
project . getTasks ( ) . withType ( Test . class ,
project . getTasks ( ) . withType ( Test . class ,
test - > {
test - > {
configureTests ( project , test ) ;
configureTests ( project , test ) ;
@ -81,20 +80,16 @@ class TestConventions {
) ;
) ;
}
}
private void configureMockito Agent ( Project project ) {
private void configureByteBuddy Agent ( Project project ) {
if ( project . hasProperty ( "mockito Version" ) ) {
if ( project . hasProperty ( "byteBuddy Version" ) ) {
String mockito Version = ( String ) project . getProperties ( ) . get ( "mockito Version" ) ;
String byteBuddy Version = ( String ) project . getProperties ( ) . get ( "byteBuddy Version" ) ;
Configuration mockito AgentConfig = project . getConfigurations ( ) . create ( "mockitoAgent " ) ;
Configuration byteBuddy AgentConfig = project . getConfigurations ( ) . create ( "byteBuddyAgentConfig " ) ;
mockito AgentConfig. setTransitive ( false ) ;
byteBuddy AgentConfig. setTransitive ( false ) ;
Dependency mockitoCore = project . getDependencies ( ) . create ( "org.mockito:mockito-core:" + mockito Version ) ;
Dependency byteBuddyAgent = project . getDependencies ( ) . create ( "net.bytebuddy:byte-buddy-agent:" + byteBuddy Version ) ;
mockito AgentConfig. getDependencies ( ) . add ( mockitoCore ) ;
byteBuddy AgentConfig. getDependencies ( ) . add ( byteBuddyAgent ) ;
project . afterEvaluate ( p - > {
project . afterEvaluate ( p - > {
p . getTasks ( ) . withType ( Test . class , test - > test . jvmArgs ( "-javaagent:" + mockitoAgentConfig . getAsPath ( ) ) ) ;
p . getTasks ( ) . withType ( Test . class , test - > test
project . getPlugins ( ) . withId ( "org.jetbrains.kotlin.jvm" , plugin - > {
. jvmArgs ( "-javaagent:" + byteBuddyAgentConfig . getAsPath ( ) ) ) ;
project . getTasks ( ) . withType ( KotlinJvmTest . class , kotlinTest - > {
kotlinTest . jvmArgs ( "-javaagent:" + mockitoAgentConfig . getAsPath ( ) ) ;
} ) ;
} ) ;
} ) ;
} ) ;
}
}
}
}