Skip to content

Commit e979d14

Browse files
author
MohitMaliFtechiz
committed
Removed javac bash commands to compile and run test cases, now we are using the gradle tasks to compile and run test cases
1 parent e0f8fa0 commit e979d14

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

lib/build.gradle

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ android {
6767
viewBinding true
6868
}
6969
ndkVersion '21.4.7075529'
70-
71-
configurations {
72-
testCompileClasspath.extendsFrom(compileClasspath)
73-
testRuntimeClasspath.extendsFrom(testCompileClasspath)
74-
testImplementation.extendsFrom(implementation)
75-
testRuntimeOnly.extendsFrom(runtimeOnly)
76-
}
7770
}
7871

7972
dependencies {
@@ -276,21 +269,40 @@ task renameLibkiwixSoFile(type: Copy) {
276269
}
277270
}
278271

279-
task compileTestFile(type: Exec) {
280-
workingDir "${projectDir}/src/test/"
281-
commandLine 'javac', '-g', '-d', '.', '-s', '.', '-cp', 'junit-4.13.jar:' + buildDir.path +'/libs/*', 'test.java'
272+
task testSourceJar(type: Jar) {
273+
from android.sourceSets.test.java.srcDirs
274+
archiveName = 'test-sources.jar'
282275
}
283276

284-
task runTests(type: Exec) {
285-
workingDir "${projectDir}/src/test/"
277+
task compileTestFile(type: JavaCompile) {
278+
dependsOn testSourceJar
279+
source = fileTree('src/test/')
280+
destinationDirectory = file('src/test/')
281+
classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar")
282+
}
283+
284+
task runTests(type: JavaExec) {
285+
workingDir("$projectDir/src/test/")
286286
dependsOn compileTestFile
287-
commandLine 'java', '-Djava.library.path=' + buildDir.path, '-javaagent:jacoco-0.8.7/lib/jacocoagent.jar', '-cp', 'junit-4.13.jar:hamcrest-core-1.3.jar:' + buildDir.path +'/libs/*lib*.jar' + ':.', 'org.junit.runner.JUnitCore', 'test'
287+
classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar')
288+
main = 'org.junit.runner.JUnitCore'
289+
args = ['test']
290+
jvmArgs = [
291+
'-Djava.library.path=' + buildDir.path,
292+
'-javaagent:jacoco-0.8.7/lib/jacocoagent.jar'
293+
]
288294
}
289295

290-
task createCodeCoverageReport(type: Exec) {
296+
task createCodeCoverageReport(type: JavaExec) {
291297
workingDir "${projectDir}/src/test/"
292298
dependsOn runTests
293-
commandLine 'java', '-jar', 'jacoco-0.8.7/lib/jacococli.jar', 'report', 'jacoco.exec', '--classfiles', 'org/kiwix/libkiwix/', '--classfiles', 'org/kiwix/libzim/', '--html', '../../build/coverage-report', '--xml', 'coverage.xml'
299+
classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar', 'src/test/jacoco-0.8.7/lib/*')
300+
main = 'org.jacoco.cli.internal.Main'
301+
args = [
302+
'report', 'jacoco.exec',
303+
'--classfiles', 'java/org/kiwix/libkiwix/', '--classfiles', 'java/org/kiwix/libzim/',
304+
'--html', '../../build/coverage-report', '--xml', 'coverage.xml'
305+
]
294306
}
295307

296308
task checkCurrentJavaVersion() {
@@ -302,7 +314,7 @@ task checkCurrentJavaVersion() {
302314

303315
task generateHeader(type: Exec) {
304316
workingDir "${projectDir}/src/main/java/org/kiwix/"
305-
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/ ${getLibzimFiles()} ${getLibkiwixFiles()}"
317+
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/java/ ${getLibzimFiles()} ${getLibkiwixFiles()}"
306318
}
307319

308320
String getLibkiwixFiles() {

0 commit comments

Comments
 (0)