Skip to content
Permalink
Browse files

add Maven profiles: default excludes non-essential unit tests IQSS#4896

  • Loading branch information...
pdurbin committed Aug 21, 2018
1 parent 9fac614 commit 6ad8056b0ff16b2a355e56ea501025729286a208
@@ -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
@@ -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
@@ -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
-----------------

27 pom.xml
@@ -628,7 +628,32 @@
</execution>
</executions>
</plugin>
<plugin>
<!-- https://stackoverflow.com/questions/46177921/how-to-run-unit-tests-in-excludedgroups-in-maven -->
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!-- testsToExclude come from the profile-->
<excludedGroups>${testsToExclude}</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>dev</id>
<activation>
<!-- https://stackoverflow.com/questions/11824328/default-build-profile-for-maven -->
<!-- We set dev to true to developers don't have to run non-essential tests over and over. -->
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<testsToExclude>edu.harvard.iq.dataverse.NonEssentialTests</testsToExclude>
</properties>
</profile>
<profile>
<id>all-unit-tests</id>
</profile>
<!-- TODO: Add a profile to run API tests (integration tests that end in IT.java. See conf/docker-aio/run-test-suite.sh -->
</profiles>
</project>
@@ -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 {

}
@@ -5,27 +5,22 @@
*/
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;

/**
*
* @author madunlap
*/

//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" +
@@ -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,21 +9,24 @@
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")));
// FIXME: Make sure the DDI we export is valid: https://github.com/IQSS/dataverse/issues/3648
// 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() {

@@ -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");

0 comments on commit 6ad8056

Please sign in to comment.
You can’t perform that action at this time.