diff --git a/build.gradle b/build.gradle index d07a7f05..4d12ed7e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { id "org.owasp.dependencycheck" version "7.1.2" id "com.diffplug.spotless" version "6.10.0" id 'jacoco' + id 'info.solidsoft.pitest' version '1.7.4' id 'se.patrikerdes.use-latest-versions' version '0.2.18' id 'com.github.ben-manes.versions' version '0.42.0' } @@ -72,6 +73,8 @@ dependencies { testImplementation 'org.testcontainers:postgresql' testImplementation 'com.tngtech.archunit:archunit-junit5:1.0.0-rc1' testImplementation 'io.rest-assured:spring-mock-mvc' + testImplementation 'org.hamcrest:hamcrest-core:2.2' + testImplementation 'org.pitest:pitest-junit5-plugin:1.0.0' } dependencyManagement { @@ -213,6 +216,36 @@ jacocoTestCoverageVerification { } } +// pitest mutation testing +pitest { + targetClasses = ['net.hostsharing.hsadminng.**'] + excludedClasses = [ + 'net.hostsharing.hsadminng.config.**', + 'net.hostsharing.hsadminng.generated.**' + ] + + targetTests = ['net.hostsharing.hsadminng.**.*UnitTest', 'net.hostsharing.hsadminng.**.*RestTest'] + excludedTestClasses = ['**AcceptanceTest*', '**IntegrationTest*'] + + pitestVersion = '1.9.0' + junit5PluginVersion = '1.0.0' + + threads = 4 + + // As Java unit tests are pretty pointless in our case, this maybe makes not much sense. + mutationThreshold = 31 + coverageThreshold = 44 + testStrengthThreshold = 76 + + outputFormats = ['XML', 'HTML'] + timestampedReports = false +} +project.tasks.check.dependsOn(project.tasks.pitest) +project.tasks.pitest.doLast { + println "PiTest Mutation Report: file:///${project.rootDir}/build/reports/pitest/index.html" +} + + // Dependency Versions Upgrade useLatestVersions { finalizedBy check diff --git a/gradle.properties b/gradle.properties index eca52c92..db7cb96e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,9 @@ postgresql.version = 42.4.1 # TODO: can be removed if all dependencies are JDK 16 compliant -#org.gradle.jvmargs= \ -# --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ -# --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ -# --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ -# --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ -# --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED +org.gradle.jvmargs= \ + --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchUnitTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchTest.java similarity index 89% rename from src/test/java/net/hostsharing/hsadminng/arch/ArchUnitTest.java rename to src/test/java/net/hostsharing/hsadminng/arch/ArchTest.java index ec715867..2210d5e3 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchTest.java @@ -1,7 +1,6 @@ package net.hostsharing.hsadminng.arch; import com.tngtech.archunit.junit.AnalyzeClasses; -import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.lang.ArchRule; import net.hostsharing.hsadminng.Accepts; import org.junit.jupiter.api.Test; @@ -11,61 +10,61 @@ import org.springframework.web.bind.annotation.RestController; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*; import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices; -@AnalyzeClasses(packages = ArchUnitTest.NET_HOSTSHARING_HSADMINNG) -public class ArchUnitTest { +@AnalyzeClasses(packages = ArchTest.NET_HOSTSHARING_HSADMINNG) +public class ArchTest { public static final String NET_HOSTSHARING_HSADMINNG = "net.hostsharing.hsadminng"; - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule contextPackageRule = classes() .that().resideInAPackage("..context..") .should().onlyDependOnClassesThat() .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule configPackageRule = classes() .that().resideInAPackage("..config..") .should().onlyDependOnClassesThat() .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule errorsPackageRule = classes() .that().resideInAPackage("..errors..") .should().onlyDependOnClassesThat() .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule hsPackagesRule = classes() .that().resideInAPackage("..hs.(*)..") .should().onlyBeAccessed().byClassesThat() .resideInAnyPackage("..hs.(*).."); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule hsPackagePackageRule = classes() .that().resideInAPackage("..hs.hspackage..") .should().onlyBeAccessed().byClassesThat() .resideInAnyPackage("..hs.hspackage.."); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule acceptsAnnotationOnMethodsRule = methods() .that().areAnnotatedWith(Accepts.class) .should().beDeclaredInClassesThat().haveSimpleNameEndingWith("AcceptanceTest") .orShould().beDeclaredInClassesThat().haveSimpleNameNotContaining("AcceptanceTest$"); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule acceptsAnnotationOnClasesRule = classes() .that().areAnnotatedWith(Accepts.class) .should().haveSimpleNameEndingWith("AcceptanceTest") .orShould().haveSimpleNameNotContaining("AcceptanceTest$"); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule doNotUseJavaxTransactionAnnotationAtClassLevel = noClasses() .should().beAnnotatedWith(javax.transaction.Transactional.class.getName()) @@ -73,7 +72,7 @@ public class ArchUnitTest { org.springframework.transaction.annotation.Transactional.class.getName(), javax.transaction.Transactional.class)); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule doNotUseJavaxTransactionAnnotationAtMethodLevel = noMethods() .should().beAnnotatedWith(javax.transaction.Transactional.class) @@ -81,7 +80,7 @@ public class ArchUnitTest { org.springframework.transaction.annotation.Transactional.class.getName(), javax.transaction.Transactional.class.getName())); - @ArchTest + @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule doNotUseOrgJUnitTestAnnotation = noMethods() .should().beAnnotatedWith(org.junit.Test.class)