diff --git a/.travis.yml b/.travis.yml index 931f29f3f93..94f9d80f715 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: java jdk: - oraclejdk8 -script: mvn -DcompilerArgument=-Xlint:unchecked test +script: mvn -DcompilerArgument=-Xlint:unchecked test -P all-unit-tests after_success: mvn jacoco:report coveralls:report diff --git a/conf/docker-aio/run-test-suite.sh b/conf/docker-aio/run-test-suite.sh index 33fe2de4685..d6cfc65710b 100755 --- a/conf/docker-aio/run-test-suite.sh +++ b/conf/docker-aio/run-test-suite.sh @@ -7,4 +7,5 @@ if [ -z "$dvurl" ]; then fi # Please note the "dataverse.test.baseurl" is set to run for "all-in-one" Docker environment. +# TODO: Rather than hard-coding the list of "IT" classes here, add a profile to pom.xml. mvn test -Dtest=DataversesIT,DatasetsIT,SwordIT,AdminIT,BuiltinUsersIT,UsersIT,UtilIT,ConfirmEmailIT,FileMetadataIT,FilesIT,SearchIT,InReviewWorkflowIT,HarvestingServerIT -Ddataverse.test.baseurl=$dvurl diff --git a/doc/sphinx-guides/source/developers/testing.rst b/doc/sphinx-guides/source/developers/testing.rst index 5492ad916b6..36803afd6fa 100755 --- a/doc/sphinx-guides/source/developers/testing.rst +++ b/doc/sphinx-guides/source/developers/testing.rst @@ -75,6 +75,17 @@ You might find studying the following test classes helpful in writing tests for In addition, there is a writeup on "The Testable Command" at https://github.com/IQSS/dataverse/blob/develop/doc/theTestableCommand/TheTestableCommand.md . +Running Non-Essential (Excluded) Unit Tests +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +You should be aware that some unit tests have been deemed "non-essential" and have been annotated with ``@Category(NonEssentialTests.class)`` and are excluded from the "dev" Maven profile, which is the default profile. All unit tests (that have not been annotated with ``@Ignore``), including these non-essential tests, are run from continuous integration systems such as Jenkins and Travis CI with the following ``mvn`` command that invokes a non-default profile: + +``mvn test -P all-unit-tests`` + +Typically https://travis-ci.org/IQSS/dataverse will show a higher number of unit tests executed because it uses the profile above. + +Generally speaking, unit tests have been flagged as non-essential because they are slow or because they require an Internet connection. You should not feel obligated to run these tests continuously but you can use the ``mvn`` command above to run them. To iterate on the unit test in Netbeans and execute it with "Run -> Test File", you must temporarily comment out the annotation flagging the test as non-essential. + Integration Tests ----------------- diff --git a/pom.xml b/pom.xml index 38bb295e5fe..690f2d11828 100644 --- a/pom.xml +++ b/pom.xml @@ -628,7 +628,32 @@ + + + maven-surefire-plugin + 2.22.0 + + + ${testsToExclude} + + - + + + dev + + + + true + + + edu.harvard.iq.dataverse.NonEssentialTests + + + + all-unit-tests + + + diff --git a/src/test/java/edu/harvard/iq/dataverse/NonEssentialTests.java b/src/test/java/edu/harvard/iq/dataverse/NonEssentialTests.java new file mode 100644 index 00000000000..612904cbd26 --- /dev/null +++ b/src/test/java/edu/harvard/iq/dataverse/NonEssentialTests.java @@ -0,0 +1,10 @@ +package edu.harvard.iq.dataverse; + +/** + * Tests annotated as non-essential will not be run by default on developers' + * laptops but they will run on continuous integration platforms like Travis CI. + * To work on one of these tests, you have to comment out the annotation. + */ +public interface NonEssentialTests { + +} diff --git a/src/test/java/edu/harvard/iq/dataverse/provenance/ProvInvestigatorTest.java b/src/test/java/edu/harvard/iq/dataverse/provenance/ProvInvestigatorTest.java index 903429c30f3..a2ecfa77cc5 100644 --- a/src/test/java/edu/harvard/iq/dataverse/provenance/ProvInvestigatorTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/provenance/ProvInvestigatorTest.java @@ -5,19 +5,15 @@ */ package edu.harvard.iq.dataverse.provenance; -import edu.harvard.iq.dataverse.provenance.ProvEntityFileData; -import edu.harvard.iq.dataverse.provenance.ProvInvestigator; import com.google.gson.JsonParser; -import com.google.gson.JsonObject; -import edu.harvard.iq.dataverse.api.AbstractApiBeanTest; +import edu.harvard.iq.dataverse.NonEssentialTests; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; import java.util.logging.Logger; import static org.junit.Assert.*; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * @@ -25,7 +21,6 @@ */ //Fix this ignore when we classify our tests, these tests are slow and unimportant -@Ignore public class ProvInvestigatorTest { private ProvInvestigator provUtilBean; @@ -38,6 +33,7 @@ public void setUp() { jsonParser = new JsonParser(); } + @Category(NonEssentialTests.class) @Test public void testProvValidator() { String validJsonString = "{\n" + @@ -109,6 +105,7 @@ public void testProvValidator() { } + @Category(NonEssentialTests.class) @Test public void testProvNamesNotInsideEntity() throws IOException { //name and type on their own @@ -126,7 +123,7 @@ public void testProvNamesNotInsideEntity() throws IOException { //MAD: write a simple entity test as well, also ensure logging works after getting a real tostring together //also write a test of parsing different cases, we don't want to catch "fakename" but we do want to catch "rdt:name" and "name" - + @Category(NonEssentialTests.class) @Test public void testProvNameJsonParserEmptyEntities() throws IOException { String jsonString = "{\n" + @@ -166,6 +163,7 @@ public void testProvNameJsonParserEmptyEntities() throws IOException { //Note: this test has entity tags in multiple places, all with unique names //Only one entity is added to our list per unique name. + @Category(NonEssentialTests.class) @Test public void testProvJsonWithEntitiesInMultiplePlaces() throws IOException { String jsonString = "{\n" + @@ -238,6 +236,7 @@ public void testProvJsonWithEntitiesInMultiplePlaces() throws IOException { assertTrue(entities.size() == 7); } + @Category(NonEssentialTests.class) @Test public void testProvJsonWithEntitiesInMultiplePlacesWithSameNames() throws IOException { String jsonString = "{\n" + @@ -276,7 +275,7 @@ public void testProvJsonWithEntitiesInMultiplePlacesWithSameNames() throws IOExc assertTrue(entities.size() == 3); //ex:report2 & ex:report1 are repeated } - @Ignore + @Category(NonEssentialTests.class) @Test public void testProvLongJsonWithEntities() throws IOException { String jsonString = "{\n" + diff --git a/src/test/java/edu/harvard/iq/dataverse/util/xml/XmlValidatorTest.java b/src/test/java/edu/harvard/iq/dataverse/util/xml/XmlValidatorTest.java index ed4652805c5..2d9c31305d5 100644 --- a/src/test/java/edu/harvard/iq/dataverse/util/xml/XmlValidatorTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/util/xml/XmlValidatorTest.java @@ -1,5 +1,6 @@ package edu.harvard.iq.dataverse.util.xml; +import edu.harvard.iq.dataverse.NonEssentialTests; import java.io.IOException; import java.net.URL; import java.util.logging.Logger; @@ -8,13 +9,16 @@ import static org.junit.Assert.assertTrue; import org.junit.Ignore; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.xml.sax.SAXException; public class XmlValidatorTest { private static final Logger logger = Logger.getLogger(XmlValidatorTest.class.getCanonicalName()); + // FIXME: Remove @Ignore after figuring out why `mvn` (but not NetBeans) shows "javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; Premature end of file" @Ignore + @Category(NonEssentialTests.class) @Test public void testValidateXml() throws IOException, SAXException, ParserConfigurationException { assertTrue(XmlValidator.validateXmlSchema("src/test/java/edu/harvard/iq/dataverse/util/xml/sendToDataCite.xml", new URL("https://schema.datacite.org/meta/kernel-3/metadata.xsd"))); @@ -22,7 +26,7 @@ public void testValidateXml() throws IOException, SAXException, ParserConfigurat // assertTrue(XmlValidator.validateXml("src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch1.xml", new URL("http://www.ddialliance.org/Specification/DDI-Codebook/2.5/XMLSchema/codebook.xsd"))); } - @Ignore + @Category(NonEssentialTests.class) @Test public void testWellFormedXml() { diff --git a/src/test/java/edu/harvard/iq/dataverse/worldmapauth/WorldMapTokenTest.java b/src/test/java/edu/harvard/iq/dataverse/worldmapauth/WorldMapTokenTest.java index 055cf1b07a0..94380d95651 100644 --- a/src/test/java/edu/harvard/iq/dataverse/worldmapauth/WorldMapTokenTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/worldmapauth/WorldMapTokenTest.java @@ -7,12 +7,14 @@ package edu.harvard.iq.dataverse.worldmapauth; import edu.harvard.iq.dataverse.DataFile; +import edu.harvard.iq.dataverse.NonEssentialTests; import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; import java.sql.Timestamp; import java.util.Date; import javax.ejb.embeddable.EJBContainer; import static org.junit.Assert.assertEquals; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * @@ -54,6 +56,7 @@ private WorldMapToken makeNewToken(TokenApplicationType tat){ return token; } + @Category(NonEssentialTests.class) @Test public void testTokenValues(){ msgt("WorldMapTokenTest!"); @@ -73,6 +76,7 @@ public void testTokenValues(){ assertEquals(token2.getToken().equalsIgnoreCase(token3.getToken()), false); } + @Category(NonEssentialTests.class) @Test public void testTokenTimes(){ msgt("testTokenTimes");