From fcb8a9b0ed770d46bbc0067855ba0e34cc1ef030 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Sun, 6 Dec 2020 12:08:42 +0100 Subject: [PATCH] DATAES-994 Add setup for mutation testing. Original PR: #568 --- TESTING.adoc | 41 +++++++++++++++ pom.xml | 20 ++++++++ .../core/geo/GeoPointUnitTests.java | 51 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 TESTING.adoc create mode 100644 src/test/java/org/springframework/data/elasticsearch/core/geo/GeoPointUnitTests.java diff --git a/TESTING.adoc b/TESTING.adoc new file mode 100644 index 000000000..0f9b44704 --- /dev/null +++ b/TESTING.adoc @@ -0,0 +1,41 @@ += Testing + +== Unit tests + +Unit tests in the project are run with + +---- +./mvnw test +---- + +== Integration tests + +Integration tests are executed when +---- +./mvnw verify +---- +is run. There must be _docker_ running, as the integration tests use docker to start an Elasticsearch server. + +Integration tests are tests that have the Junit5 Tag `@Tag("integration-test")` on the test class. Normally this should not be set explicitly, but the annotation `@SpringIntegrationTest` should be used. This not only marks the test as integration test, but integrates an automatic setup of an Elasticsearch Testcontainer and integrate this with Spring, so +that the required Beans can be automatically injected. Check _src/test/java/org/springframework/data/elasticsearch/JUnit5SampleRestClientBasedTests.java_ as a reference setup + +== Mutation testing + +The pom includes a plugin dependency to run mutation tests using [pitest](https://pitest.org/). These tests must be explicitly configured and run, they are not included in the normal build steps. Before pitest can run, a normal `./mvnw test` must be executed. The configuration excludes integration tests, only unit tests are considered. + + +pitest can be run directly from the commandline +---- +./mvnw org.pitest:pitest-maven:mutationCoverage +---- +This will output an html report to _target/pit-reports/YYYYMMDDHHMI_. + +To speed-up repeated analysis of the same codebase set the withHistory parameter to true. +---- +./mvnw -DwithHistory org.pitest:pitest-maven:mutationCoverage +---- + +The classes to test are defined either in the pom.xml or can be set on the commandline: +---- +./mvnw -DwithHistory org.pitest:pitest-maven:mutationCoverage -DtargetClasses="org.springframework.data.elasticsearch.support.*" +---- diff --git a/pom.xml b/pom.xml index a7a126bae..749d49c00 100644 --- a/pom.xml +++ b/pom.xml @@ -366,6 +366,26 @@ + + org.pitest + pitest-maven + 1.5.2 + + + org.pitest + pitest-junit5-plugin + 0.12 + + + + integration-test + + org.springframework.data.elasticsearch.core.geo.* + + toString + + + org.apache.maven.plugins maven-assembly-plugin diff --git a/src/test/java/org/springframework/data/elasticsearch/core/geo/GeoPointUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/core/geo/GeoPointUnitTests.java new file mode 100644 index 000000000..fc504aa79 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/geo/GeoPointUnitTests.java @@ -0,0 +1,51 @@ +package org.springframework.data.elasticsearch.core.geo; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.data.geo.Point; + +/** + * @author P.J. Meisch (pj.meisch@sothawo.com) + */ +class GeoPointUnitTests { + + @Test + @DisplayName("should create From a Point") + void shouldCreateFromAPoint() { + Point point = new Point(8, 48); + + GeoPoint geoPoint = GeoPoint.fromPoint(point); + + assertThat(geoPoint).isEqualTo(new GeoPoint(48, 8)); + } + + @Test + @DisplayName("should convert to a Point") + void shouldConvertToAPoint() { + + GeoPoint geoPoint = new GeoPoint(48, 8); + + Point point = GeoPoint.toPoint(geoPoint); + + assertThat(point).isEqualTo(new Point(8, 48)); + } + + @Test + @DisplayName("should not be equal to a Point") + void shouldNotBeEqualToAPoint() { + + //noinspection AssertBetweenInconvertibleTypes + assertThat(new GeoPoint(48, 8)).isNotEqualTo(new Point(8, 48)); + } + + @Test + @DisplayName("should compare lat and lon values") + void shouldCompareLatAndLonValues() { + + GeoPoint geoPoint = new GeoPoint(48, 8); + + assertThat(geoPoint).isEqualTo(new GeoPoint(48, 8)); + } +}