From 84235ee8224fca1751df21a79e2ee7e1e0cf75b6 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 31 Mar 2023 15:58:59 +0530 Subject: [PATCH] Removed javac bash commands to compile and run test cases, now we are using the gradle tasks to compile and run test cases --- lib/build.gradle | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 2e6ff65..f03e660 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -67,13 +67,6 @@ android { viewBinding true } ndkVersion '21.4.7075529' - - configurations { - testCompileClasspath.extendsFrom(compileClasspath) - testRuntimeClasspath.extendsFrom(testCompileClasspath) - testImplementation.extendsFrom(implementation) - testRuntimeOnly.extendsFrom(runtimeOnly) - } } dependencies { @@ -274,21 +267,40 @@ task renameLibkiwixSoFile(type: Copy) { } } -task compileTestFile(type: Exec) { - workingDir "${projectDir}/src/test/" - commandLine 'javac', '-g', '-d', '.', '-s', '.', '-cp', 'junit-4.13.jar:' + buildDir.path +'/libs/*', 'test.java' +task testSourceJar(type: Jar) { + from android.sourceSets.test.java.srcDirs + archiveName = 'test-sources.jar' } -task runTests(type: Exec) { - workingDir "${projectDir}/src/test/" +task compileTestFile(type: JavaCompile) { + dependsOn testSourceJar + source = fileTree('src/test/') + destinationDirectory = file('src/test/') + classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar") +} + +task runTests(type: JavaExec) { + workingDir("$projectDir/src/test/") dependsOn compileTestFile - 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' + classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar') + main = 'org.junit.runner.JUnitCore' + args = ['test'] + jvmArgs = [ + '-Djava.library.path=' + buildDir.path, + '-javaagent:jacoco-0.8.7/lib/jacocoagent.jar' + ] } -task createCodeCoverageReport(type: Exec) { +task createCodeCoverageReport(type: JavaExec) { workingDir "${projectDir}/src/test/" dependsOn runTests - 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' + 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/*') + main = 'org.jacoco.cli.internal.Main' + args = [ + 'report', 'jacoco.exec', + '--classfiles', 'java/org/kiwix/libkiwix/', '--classfiles', 'java/org/kiwix/libzim/', + '--html', '../../build/coverage-report', '--xml', 'coverage.xml' + ] } task checkCurrentJavaVersion() { @@ -300,7 +312,7 @@ task checkCurrentJavaVersion() { task generateHeader(type: Exec) { workingDir "${projectDir}/src/main/java/org/kiwix/" - commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/ ${getLibzimFiles()} ${getLibkiwixFiles()}" + commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/java/ ${getLibzimFiles()} ${getLibkiwixFiles()}" } String getLibkiwixFiles() {