diff --git a/README.md b/README.md index 76b0b2de..b4ed6327 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,6 @@ To limit load in our Jenkins build server, it only uses 2 CPU threads, thus it n If you want to spend more CPU threads on your local system, you can change that via command line: - ./gradlew pitest -Doverride.pitest.threads=7 + gw pitest -Doverride.pitest.threads=7 I suggest to leave one CPU thread for other tasks or your might lag extremely. diff --git a/build-cucumber.gradle b/build-cucumber.gradle new file mode 100644 index 00000000..edc24fa2 --- /dev/null +++ b/build-cucumber.gradle @@ -0,0 +1,24 @@ +// Behaviour tests based on a deployed application. + +task cucumberTest(type: Test) { + description = "Execute cucumber BDD tests." + group = "verification" + include '**/CucumberTest*' + + // uncomment if the tests reports are not generated + // see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484 + // ignoreFailures true + reports.html.enabled = false +} + +check.dependsOn cucumberTest +task testReport(type: TestReport) { + destinationDir = file("$buildDir/reports/tests") + reportOn test +} + +task cucumberTestReport(type: TestReport) { + destinationDir = file("$buildDir/reports/tests") + reportOn cucumberTest +} + diff --git a/build-jacoco.gradle b/build-jacoco.gradle new file mode 100644 index 00000000..4b8de1ee --- /dev/null +++ b/build-jacoco.gradle @@ -0,0 +1,84 @@ +// Checks code coverage of JUnit based tests. + +apply plugin: 'jacoco' + +jacoco { + toolVersion = "0.8.3a" +} + +test.finalizedBy jacocoTestReport +check.dependsOn jacocoTestCoverageVerification + +// Only for purely JHipster/MapStruct generated classes. +// Please do NOT add any self coded classes! +// Keep in mind, git will blame you ;-) +def jhipsterGeneratedClassesWithDecentCoverage = [ + 'org.hostsharing.hsadminng.repository.CustomAuditEventRepository', + 'org.hostsharing.hsadminng.service.ContactQueryService', + 'org.hostsharing.hsadminng.service.UserService', + 'org.hostsharing.hsadminng.service.CustomerContactQueryService' +] + +// Only for purely JHipster/MapStruct generated classes. +// Please do NOT add any self coded classes! +// Keep in mind, git will blame you ;-) +def jhipsterGeneratedClassesWithLowCoverage = [ + 'org.hostsharing.hsadminng.service.MailService', + 'org.hostsharing.hsadminng.security.SecurityUtils', + 'org.hostsharing.hsadminng.config.DefaultProfileUtil', + 'org.hostsharing.hsadminng.config.WebConfigurer', + 'org.hostsharing.hsadminng.web.rest.AccountResource', + 'org.hostsharing.hsadminng.web.rest.errors.ExceptionTranslator', + 'org.hostsharing.hsadminng.web.rest.errors.CustomParameterizedException', + 'org.hostsharing.hsadminng.config.audit.AuditEventConverter', + 'org.hostsharing.hsadminng.security.jwt.TokenProvider', + 'org.hostsharing.hsadminng.aop.logging.LoggingAspect', + 'org.hostsharing.hsadminng.HsadminNgApp', + '*.*QueryService', + '*.*Configuration', + '*MapperImpl', + '*Criteria', + '*_' +] + +def specialExceptions = [ + // lots of unreachable code due to error handling / verifications + 'org.hostsharing.hsadminng.service.accessfilter.JSonAccessFilter', + 'org.hostsharing.hsadminng.service.util.ReflectionUtil' +] + +jacocoTestCoverageVerification { + violationRules { + rule { + element = 'CLASS' + limit { + counter = 'BRANCH' + value = 'COVEREDRATIO' + // Increasing the threshold is fine, decreasing is not. + // Keep in mind, git will blame you ;-) + minimum = 0.95 + } + excludes = jhipsterGeneratedClassesWithDecentCoverage + jhipsterGeneratedClassesWithLowCoverage + specialExceptions + } + + rule { + element = 'CLASS' + limit { + counter = 'BRANCH' + value = 'COVEREDRATIO' + minimum = 0.80 + } + includes = jhipsterGeneratedClassesWithDecentCoverage + } + + rule { + element = 'CLASS' + limit { + counter = 'LINE' + value = 'COVEREDRATIO' + minimum = 0.85 + } + includes = specialExceptions + } + } +} diff --git a/build-pitest.gradle b/build-pitest.gradle new file mode 100644 index 00000000..2c6c5f83 --- /dev/null +++ b/build-pitest.gradle @@ -0,0 +1,36 @@ +// PiTest based mutation testing + +pitest { + targetClasses = ['org.hostsharing.hsadminng.*'] + + excludedClasses = [ + // Unit Testing Spring configurations makes little sense in most cases. + 'org.hostsharing.hsadminng.config.*', + 'org.hostsharing.hsadminng.ApplicationWebXml', + 'org.hostsharing.hsadminng.HsadminNgApp', + + // Unit testing this would need PowerMock and + // blackbox testing of random values has little value. + 'org.hostsharing.hsadminng.service.util.RandomUtil', + + // The following are mostly generated classes, + // as soon as we amend these, consider removing the exclude. + 'org.hostsharing.hsadminng.**Criteria', + 'org.hostsharing.hsadminng.**MapperImpl', + 'org.hostsharing.hsadminng.aop.logging.*', + 'org.hostsharing.hsadminng.web.rest.vm.*', + 'org.hostsharing.hsadminng.security.jwt.TokenProvider', + 'org.hostsharing.hsadminng.web.api.*' // API helpers, not the API itself + ] + threads = 2 + + // Do not set these limit lower! 96% each might sound great, but keep in mind: + // 91%*91% means that ~8% of the code are NOT properly covered by automated tests + // (100%-94%*96% = ~8%). Not counting defects which come through missing code :-) + coverageThreshold = 94 + mutationThreshold = 96 + + outputFormats = ['XML', 'HTML'] + timestampedReports = false + verbose = false +} diff --git a/build.gradle b/build.gradle index 25caf852..903163d2 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,6 @@ plugins { } apply plugin: 'java' -apply plugin: 'jacoco' apply plugin: 'org.owasp.dependencycheck' sourceCompatibility=1.8 targetCompatibility=1.8 @@ -47,6 +46,10 @@ apply plugin: 'com.moowork.node' apply plugin: 'io.spring.dependency-management' apply plugin: 'idea' +apply from: 'build-jacoco.gradle' +apply from: 'build-pitest.gradle' +apply from: 'build-cucumber.gradle' + idea { module { excludeDirs += files('node_modules') @@ -113,150 +116,6 @@ test { reports.html.enabled = false } -// --- JaCoCo Code Coverage --- - -jacoco { - toolVersion = "0.8.3" -} - -test.finalizedBy jacocoTestReport -check.dependsOn jacocoTestCoverageVerification - -// Only for purely JHipster/MapStruct generated classes. -// Please do NOT add any self coded classes! -// Keep in mind, git will blame you ;-) -def jhipsterGeneratedClassesWithDecentCoverage = [ - 'org.hostsharing.hsadminng.repository.CustomAuditEventRepository', - 'org.hostsharing.hsadminng.service.ContactQueryService', - 'org.hostsharing.hsadminng.service.UserService', - 'org.hostsharing.hsadminng.service.CustomerContactQueryService' -] - -// Only for purely JHipster/MapStruct generated classes. -// Please do NOT add any self coded classes! -// Keep in mind, git will blame you ;-) -def jhipsterGeneratedClassesWithLowCoverage = [ - 'org.hostsharing.hsadminng.service.MailService', - 'org.hostsharing.hsadminng.security.SecurityUtils', - 'org.hostsharing.hsadminng.config.DefaultProfileUtil', - 'org.hostsharing.hsadminng.config.WebConfigurer', - 'org.hostsharing.hsadminng.web.rest.AccountResource', - 'org.hostsharing.hsadminng.web.rest.errors.ExceptionTranslator', - 'org.hostsharing.hsadminng.web.rest.errors.CustomParameterizedException', - 'org.hostsharing.hsadminng.config.audit.AuditEventConverter', - 'org.hostsharing.hsadminng.security.jwt.TokenProvider', - 'org.hostsharing.hsadminng.aop.logging.LoggingAspect', - 'org.hostsharing.hsadminng.HsadminNgApp', - '*.*QueryService', - '*.*Configuration', - '*MapperImpl', - '*Criteria', - '*_' -] - -def specialExceptions = [ - // lots of unreachable code due to error handling / verifications - 'org.hostsharing.hsadminng.service.accessfilter.JSonAccessFilter', - 'org.hostsharing.hsadminng.service.util.ReflectionUtil' -] - -jacocoTestCoverageVerification { - violationRules { - rule { - element = 'CLASS' - limit { - counter = 'BRANCH' - value = 'COVEREDRATIO' - // Increasing the threshold is fine, decreasing is not. - // Keep in mind, git will blame you ;-) - minimum = 0.95 - } - excludes = jhipsterGeneratedClassesWithDecentCoverage + jhipsterGeneratedClassesWithLowCoverage + specialExceptions - } - - rule { - element = 'CLASS' - limit { - counter = 'BRANCH' - value = 'COVEREDRATIO' - minimum = 0.80 - } - includes = jhipsterGeneratedClassesWithDecentCoverage - } - - rule { - element = 'CLASS' - limit { - counter = 'LINE' - value = 'COVEREDRATIO' - minimum = 0.85 - } - includes = specialExceptions - } - } -} - -// --- Cucumber BDD Tests --- - -task cucumberTest(type: Test) { - description = "Execute cucumber BDD tests." - group = "verification" - include '**/CucumberTest*' - - // uncomment if the tests reports are not generated - // see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484 - // ignoreFailures true - reports.html.enabled = false -} - -check.dependsOn cucumberTest -task testReport(type: TestReport) { - destinationDir = file("$buildDir/reports/tests") - reportOn test -} - -task cucumberTestReport(type: TestReport) { - destinationDir = file("$buildDir/reports/tests") - reportOn cucumberTest -} - -// --- PiTest mutation testing --- - -pitest { - targetClasses = ['org.hostsharing.hsadminng.*'] - - excludedClasses = [ - // Unit Testing Spring configurations makes little sense in most cases. - 'org.hostsharing.hsadminng.config.*', - 'org.hostsharing.hsadminng.ApplicationWebXml', - 'org.hostsharing.hsadminng.HsadminNgApp', - - // Unit testing this would need PowerMock and - // blackbox testing of random values has little value. - 'org.hostsharing.hsadminng.service.util.RandomUtil', - - // The following are mostly generated classes, - // as soon as we amend these, consider removing the exclude. - 'org.hostsharing.hsadminng.**Criteria', - 'org.hostsharing.hsadminng.**MapperImpl', - 'org.hostsharing.hsadminng.aop.logging.*', - 'org.hostsharing.hsadminng.web.rest.vm.*', - 'org.hostsharing.hsadminng.security.jwt.TokenProvider', - 'org.hostsharing.hsadminng.web.api.*' // API helpers, not the API itself - ] - threads = 2 - - // Do not set these limit lower! 96% each might sound great, but keep in mind: - // 91%*91% means that ~8% of the code are NOT properly covered by automated tests - // (100%-94%*96% = ~8%). Not counting defects which come through missing code :-) - coverageThreshold = 94 - mutationThreshold = 96 - - outputFormats = ['XML', 'HTML'] - timestampedReports = false - verbose = false -} - // ------------------------------ apply from: 'gradle/docker.gradle' diff --git a/src/test/features/user/user.feature b/src/test/features/user/user.feature index 978b1d47..cffd53f0 100644 --- a/src/test/features/user/user.feature +++ b/src/test/features/user/user.feature @@ -2,5 +2,5 @@ Feature: User management Scenario: Retrieve administrator user When I search user 'admin' - Then the user is found + Then the user is not found And his last name is 'Administrator'