blob: 1e7481bda61f61ff27d349cfbaa262638a109017 [file] [log] [blame]
Alex Volanis7004a612018-01-24 10:30:13 -05001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20// Following Gradle best practices to keep build logic organized
21
22// Bundle the test classes in a JAR for other Ant based builds
23task testJar(type: Jar, group: 'Build') {
24 description = 'Assembles a jar archive containing the test classes.'
25 project.test.dependsOn it
26
Jiayu Liube73a572023-04-14 11:02:43 +080027 archiveClassifier = 'test'
Alex Volanis7004a612018-01-24 10:30:13 -050028 from sourceSets.test.output
29}
30
31// ----------------------------------------------------------------------------
32// Unit test tasks and configurations
33
34// Help the up to date algorithm to make these tests done
35ext.markTaskDone = { task ->
36 def buildFile = file("$buildDir/${task.name}.flag")
37 task.inputs.files task.classpath
38 task.outputs.file buildFile
39 task.doLast {
40 buildFile.text = 'Passed!'
41 }
42}
43
44task deprecatedEqualityTest(type: JavaExec, group: 'Verification') {
45 description = 'Run the non-JUnit test suite '
46 classpath = sourceSets.test.runtimeClasspath
Jiayu Liu5b158382022-05-12 00:20:37 +080047 mainClass.set('org.apache.thrift.test.EqualityTest')
Alex Volanis7004a612018-01-24 10:30:13 -050048 markTaskDone(it)
49}
50
51task deprecatedJavaBeansTest(type: JavaExec, group: 'Verification') {
52 description = 'Run the non-JUnit test suite '
53 classpath = sourceSets.test.runtimeClasspath
Jiayu Liu5b158382022-05-12 00:20:37 +080054 mainClass.set('org.apache.thrift.test.JavaBeansTest')
Alex Volanis7004a612018-01-24 10:30:13 -050055 markTaskDone(it)
56}
57
58// Main Unit Test task configuration
59test {
60 description="Run the full test suite"
61 dependsOn deprecatedEqualityTest, deprecatedJavaBeansTest
62
63 // Allow repeating tests even after successful execution
64 if (project.hasProperty('rerunTests')) {
65 outputs.upToDateWhen { false }
66 }
67
Jiayu Liu92b007f2022-10-14 13:16:18 +080068 // This is required for Mockito to run under Java 17
69 jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
Alex Volanis7004a612018-01-24 10:30:13 -050070 include '**/Test*.class'
71 exclude '**/Test*\$*.class'
72
Jiayu Liu0c9c9df2022-05-06 03:30:52 +080073 // https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle
74 useJUnitPlatform() {
75 // https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution
76 systemProperty("junit.jupiter.execution.parallel.enabled", "true")
77 systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
78 systemProperty("junit.jupiter.execution.parallel.mode.classes.default", "concurrent")
79 }
80
Alex Volanis7004a612018-01-24 10:30:13 -050081 maxHeapSize = '512m'
Alex Volanis7004a612018-01-24 10:30:13 -050082
83 systemProperties = [
84 'build.test': "${compileTestJava.destinationDir}",
85 'test.port': "${testPort}",
Jiayu Liueac51032022-03-11 04:55:13 +010086 'javax.net.ssl.trustStore': "${projectDir}/src/crossTest/resources/.truststore",
Alex Volanis7004a612018-01-24 10:30:13 -050087 'javax.net.ssl.trustStorePassword': 'thrift',
Jiayu Liueac51032022-03-11 04:55:13 +010088 'javax.net.ssl.keyStore': "${projectDir}/src/crossTest/resources/.keystore",
Alex Volanis7004a612018-01-24 10:30:13 -050089 'javax.net.ssl.keyStorePassword': 'thrift'
90 ]
91}