Enabling writing and running of tests with scalatest. #789

Merged
merged 1 commit into from Apr 15, 2017
Jump to file or symbol
Failed to load files and symbols.
+575 −477
Split
View
@@ -10,7 +10,7 @@ cache:
- $HOME/.m2
jdk:
- oraclejdk8
-script: ./gradlew testSRA jacocoTestReport;
+script: ./gradlew test jacocoTestReport;
after_success:
- bash <(curl -s https://codecov.io/bash)
- echo "TRAVIS_BRANCH='$TRAVIS_BRANCH'";
View
@@ -5,20 +5,21 @@ buildscript {
}
plugins {
- id "java"
+ id 'java'
+ id 'scala'
id 'maven'
id 'signing'
id 'jacoco'
id 'com.palantir.git-version' version '0.5.1'
id 'com.github.johnrengelman.shadow' version '1.2.3'
+ id 'com.github.maiflai.scalatest' version '0.15'
}
repositories {
mavenCentral()
}
jacocoTestReport {
- dependsOn test
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
@@ -29,10 +30,6 @@ jacocoTestReport {
}
}
-jacoco {
- toolVersion = "0.7.5.201505241946"
-}
-
dependencies {
compile "org.apache.commons:commons-jexl:2.1.1"
compile "commons-logging:commons-logging:1.1.1"
@@ -41,6 +38,9 @@ dependencies {
compile "org.tukaani:xz:1.5"
compile "gov.nih.nlm.ncbi:ngs-java:1.2.4"
+ testCompile "org.scala-lang:scala-library:2.12.1"
+ testCompile "org.scalatest:scalatest_2.12:3.0.1"
+ testRuntime 'org.pegdown:pegdown:1.4.2' // Necessary for generating HTML reports with ScalaTest
testCompile "org.testng:testng:6.9.9"
testCompile "com.google.jimfs:jimfs:1.1"
}
@@ -67,70 +67,46 @@ jar {
import org.gradle.internal.os.OperatingSystem;
-tasks.withType(Test) {
- outputs.upToDateWhen { false } // tests will always rerun
- useTestNG()
-
- // set heap size for the test JVM(s)
- minHeapSize = "1G"
- maxHeapSize = "2G"
+tasks.withType(Test) { task ->
+ task.outputs.upToDateWhen { false } // tests will always rerun
- jvmArgs '-Djava.awt.headless=true' //this prevents awt from displaying a java icon while the tests are running
+ // Always run serially because there are some very badly behaved tests in HTSJDK that
+ // will cause errors and even deadlocks if run multi-threaded
+ task.maxParallelForks = 1
- if (System.env.CI == "true") { //if running under a CI output less into the logs
- int count = 0
+ // set heap size for the test JVM(s)
+ task.minHeapSize = "1G"
+ task.maxHeapSize = "2G"
- beforeTest { descriptor ->
- count++
- if( count % 100 == 0) {
- logger.lifecycle("Finished "+ Integer.toString(count++) + " tests")
- }
- }
- } else {
- // show standard out and standard error of the test JVM(s) on the console
- testLogging.showStandardStreams = true
- beforeTest { descriptor ->
- logger.lifecycle("Running Test: " + descriptor)
- }
+ task.jvmArgs '-Djava.awt.headless=true' //this prevents awt from displaying a java icon while the tests are running
+}
- // listen to standard out and standard error of the test JVM(s)
- onOutput { descriptor, event ->
- logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
- }
- }
+test {
+ description = "Runs the unit tests other than the SRA tests"
testLogging {
- testLogging {
- events "skipped", "failed"
- exceptionFormat = "full"
- }
- afterSuite { desc, result ->
- if (!desc.parent) { // will match the outermost suite
- println "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
- }
- }
+ events "failed", "skipped"
}
-}
-test {
- description = "Runs the unit tests other than the SRA tests"
+ if (System.env.CI == "true") {
+ jvmArgs += '-Dsamjdk.sra_libraries_download=true'
+ }
- useTestNG {
- if( OperatingSystem.current().isUnix() ){
- excludeGroups "slow", "broken", "sra"
- } else {
- excludeGroups "slow", "broken", "unix", "sra"
- }
+ tags {
+ exclude "slow"
+ exclude "broken"
+ if (System.env.CI == "false") exclude "sra"
+ if (!OperatingSystem.current().isUnix()) exclude "unix"
}
}
task testSRA(type: Test) {
- jvmArgs '-Dsamjdk.sra_libraries_download=true'
+ description = "Run the SRA tests"
+ jvmArgs += '-Dsamjdk.sra_libraries_download=true'
- description "Run the SRA tests"
- useTestNG {
- configFailurePolicy 'continue'
- includeGroups "sra"
+ tags {
+ exclude "slow"
+ exclude "broken"
}
}
@@ -1,6 +1,6 @@
-#Tue Nov 29 15:10:15 EST 2016
+#Fri Jan 20 17:10:11 EST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
@@ -0,0 +1,10 @@
+package htsjdk;
+
+import org.scalatest.testng.TestNGSuite;
+
+/**
+ * Base class for all Java tests in HTSJDK.
+ */
+public class HtsjdkTest extends TestNGSuite {
+
+}
@@ -1,16 +1,15 @@
-package htsjdk.samtools.cram.io;
+package htsjdk.cram.io;
-import org.apache.commons.compress.utils.IOUtils;
+import htsjdk.HtsjdkTest;
+import htsjdk.samtools.cram.io.ExternalCompression;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
-public class ExternalCompressionTest {
+public class ExternalCompressionTest extends HtsjdkTest {
public static final File BZIP2_FILE = new File("src/test/resources/htsjdk/samtools/cram/io/bzip2-test.bz2");
public static final byte [] TEST_BYTES = "This is a simple string to test BZip2".getBytes();
@@ -1,11 +1,12 @@
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.seekablestream.SeekableStream;
import org.testng.annotations.Test;
import java.io.IOException;
-public class AbstractBAMFileIndexTest {
+public class AbstractBAMFileIndexTest extends HtsjdkTest {
/**
* @see <a href="https://github.com/samtools/htsjdk/issues/73">https://github.com/samtools/htsjdk/issues/73</a>
@@ -59,4 +60,4 @@ public int read() throws IOException {
buffer.readInteger();
buffer.readBytes(new byte[10000]);
}
-}
+}
@@ -1,5 +1,6 @@
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.util.CloserUtil;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
@@ -10,7 +11,7 @@
* Test the fix of a bug reported by s-andrews in which the use of an arithmetic rather than a logical right shift in BinaryCigarCodec.binaryCigarToCigarElement()
* causes an overflow in the CIGAR when reading a BAM file for a read that spans a very large intron.
*/
-public class BAMCigarOverflowTest {
+public class BAMCigarOverflowTest extends HtsjdkTest {
private static final File TEST_DATA_DIR = new File("src/test/resources/htsjdk/samtools");
@Test
@@ -23,6 +23,7 @@
*/
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.util.CloseableIterator;
import htsjdk.samtools.util.CloserUtil;
import htsjdk.samtools.util.StopWatch;
@@ -46,7 +47,7 @@
/**
* Test BAM file indexing.
*/
-public class BAMFileIndexTest {
+public class BAMFileIndexTest extends HtsjdkTest {
private final File BAM_FILE = new File("src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam");
private final boolean mVerbose = false;
@@ -78,8 +79,7 @@ public void testSpecificQueries()
}
@Test(groups = {"slow"})
- public void testRandomQueries()
- throws Exception {
+ public void testRandomQueries() throws Exception {
runRandomTest(BAM_FILE, 1000, new Random());
}
@@ -23,6 +23,7 @@
*/
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.util.CloseableIterator;
import htsjdk.samtools.util.CloserUtil;
import org.testng.Assert;
@@ -35,7 +36,7 @@
* Test that BAM writing doesn't blow up. For presorted writing, the resulting BAM file is read and contents are
* compared with the original SAM file.
*/
-public class BAMFileWriterTest {
+public class BAMFileWriterTest extends HtsjdkTest {
private SAMRecordSetBuilder getRecordSetBuilder(final boolean sortForMe, final SAMFileHeader.SortOrder sortOrder) {
final SAMRecordSetBuilder ret = new SAMRecordSetBuilder(sortForMe, sortOrder);
@@ -23,6 +23,7 @@
*/
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.util.CloserUtil;
import htsjdk.samtools.util.IOUtil;
import org.testng.annotations.DataProvider;
@@ -38,7 +39,7 @@
/**
* Test BAM file index creation
*/
-public class BAMIndexWriterTest {
+public class BAMIndexWriterTest extends HtsjdkTest {
// Two input files for basic test
private final String BAM_FILE_LOCATION = "src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam";
private final String BAI_FILE_LOCATION = "src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam.bai";
@@ -23,6 +23,7 @@
*/
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.util.CloseableIterator;
import htsjdk.samtools.util.CloserUtil;
import org.testng.Assert;
@@ -34,7 +35,7 @@
/**
* @author alecw@broadinstitute.org
*/
-public class BAMIteratorTest {
+public class BAMIteratorTest extends HtsjdkTest {
private static final File TEST_DATA_DIR = new File("src/test/resources/htsjdk/samtools");
@Test(dataProvider = "dataProvider")
@@ -1,13 +1,14 @@
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Random;
-public class BAMQueryMultipleIntervalsIteratorFilterTest {
+public class BAMQueryMultipleIntervalsIteratorFilterTest extends HtsjdkTest {
private final byte[] BASES = {'A', 'C', 'G', 'T'};
private final Random random = new Random();
@@ -23,6 +23,7 @@
*/
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.util.CloserUtil;
import htsjdk.samtools.util.TestUtil;
import org.testng.annotations.Test;
@@ -40,7 +41,7 @@
/**
* Test BAM file indexing.
*/
-public class BAMRemoteFileTest {
+public class BAMRemoteFileTest extends HtsjdkTest {
private final File BAM_INDEX_FILE = new File("src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam.bai");
private final File BAM_FILE = new File("src/test/resources/htsjdk/samtools/BAMFileIndexTest/index_test.bam");
private final String BAM_URL_STRING = TestUtil.BASE_URL_FOR_HTTP_TESTS + "index_test.bam";
@@ -24,12 +24,13 @@
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Collections;
-public class BinTest {
+public class BinTest extends HtsjdkTest {
@Test
public void testEmptyBin() {
// Construct a new empty bin and ensure that the bin list is empty, not null.
@@ -1,5 +1,6 @@
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.cram.build.ContainerFactory;
import htsjdk.samtools.cram.structure.Container;
import htsjdk.samtools.cram.structure.CramCompressionRecord;
@@ -17,7 +18,7 @@
/**
* Created by vadim on 12/01/2016.
*/
-public class CRAMBAIIndexerTest {
+public class CRAMBAIIndexerTest extends HtsjdkTest {
private static CramCompressionRecord createRecord(int recordIndex, int seqId, int start) {
byte[] bases = "AAAAA".getBytes();
@@ -1,5 +1,6 @@
package htsjdk.samtools;
+import htsjdk.HtsjdkTest;
import htsjdk.samtools.cram.CRAIEntry;
import htsjdk.samtools.cram.build.CramContainerIterator;
import htsjdk.samtools.cram.ref.ReferenceSource;
@@ -17,7 +18,7 @@
* Companion to CRAMBAIIndexerTest, for testing CRAI indices created on cram
* streams;
*/
-public class CRAMCRAIIndexerTest {
+public class CRAMCRAIIndexerTest extends HtsjdkTest {
@Test
public void testCRAIIndexerFromContainer() throws IOException {
@@ -180,4 +181,4 @@ private long getIteratorCount(Iterator<SAMRecord> it) {
return count;
}
-}
+}
Oops, something went wrong.