All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.jqassistant-rules.test-impact-analysis.xml Maven / Gradle / Ivy

Go to download

The jQAssistant plugin for test impact analysis creates test suites for Maven based on changes in the version control system.

There is a newer version: 1.10.0
Show newest version
<jqa:jqassistant-rules xmlns:jqa="http://www.buschmais.com/jqassistant/core/rule/schema/v1.3">

    <concept id="test-impact-analysis:FilesChangedByLastGitCommit" severity="info">
        <description>Adds a label 'Changed' to all Git files that have been changed in the last Git commit.</description>
        <cypher><![CDATA[
            MATCH
              (:Repository)-[:HAS_HEAD]->(:Commit)-[:CONTAINS_CHANGE]->()-[:MODIFIES]->(sourceFile:File)
            WHERE
              sourceFile.relativePath ends with ".java"
            SET
              sourceFile:Changed
            RETURN
              sourceFile
        ]]></cypher>
    </concept>

    <concept id="test-impact-analysis:TypesChangedByLastGitCommit" severity="info">
        <requiresConcept refId="test-impact-analysis:FilesChangedByLastGitCommit" />
        <description>Adds a label 'Changed' to all Java types that have been changed in the last Git commit.</description>
        <cypher><![CDATA[
            MATCH
              (sourceFile:Git:File:Changed)
            WHERE
              sourceFile.relativePath ends with ".java"
            WITH
              sourceFile
            MATCH
              (package:Package)-[:CONTAINS]->(changedType:Type)
            WHERE
              sourceFile.relativePath ends with (package.fileName + "/" + changedType.sourceFileName)
            SET
              changedType:Changed
            RETURN
              changedType
        ]]></cypher>
    </concept>

    <concept id="test-impact-analysis:TestsAffectedByLastGitCommit" severity="info">
        <requiresConcept refId="test-impact-analysis:TypesChangedByLastGitCommit" />
        <requiresConcept refId="junit4:TestClass" />
        <description>Adds a label 'Affected' to all test classes having a dependency to Java types which were changed in the last Git commit.</description>
        <cypher><![CDATA[
            MATCH
              hierarchy=shortestPath((changedType:Type:Changed)-[:EXTENDS|IMPLEMENTS*0..]-(type:Type))
            WITH
              type, hierarchy
            WHERE
              all(t in nodes(hierarchy) WHERE (:Artifact)-[:CONTAINS]->(t))
            WITH
              type
            MATCH
              (testArtifact:Artifact)-[:CONTAINS]->(testPackage:Package)-[:CONTAINS]->(test:Test:Class),
              (test)-[:EXTENDS|IMPLEMENTS*0..]->(:Class)-[:DEPENDS_ON*0..1]->(type:Type)
            WHERE NOT
              (exists(test.abstract) and test.abstract)
            SET
              test:Affected
            RETURN
              testArtifact as Artifact, collect(distinct test) as Tests
        ]]></cypher>
    </concept>

    <concept id="test-impact-analysis:SurefireSuiteForLastGitCommit" severity="info">
        <requiresConcept refId="test-impact-analysis:TestsAffectedByLastGitCommit" />
        <description>Reports all test classes affected by the last Git commit.</description>
        <cypher><![CDATA[
            MATCH
              (:Maven:Project)-[:CREATES]->(artifact:Artifact)
            OPTIONAL MATCH
              (artifact)-[:CONTAINS]->(test:Affected:Test)
            RETURN
              artifact as Artifact, collect(test) as Tests
        ]]></cypher>
        <report type="surefire-suite" />
    </concept>

    <concept id="test-impact-analysis:GitBaseCommit">
        <description>Adds a label 'Base' to all commits with more than one child commits (i.e. commits where a branch is split off).</description>
        <cypher><![CDATA[
            MATCH
              (child)-[:HAS_PARENT|HAS_HEAD]->(branchBase:Commit)
            WHERE
              child:Commit or child:Branch
            WITH
              branchBase, count(child) as children
            WHERE
              children > 1
            SET
              branchBase:Base
            RETURN
              branchBase as Base, children as Children
        ]]></cypher>
    </concept>


    <concept id="test-impact-analysis:FilesChangedByCommitsInCurrentGitBranch" severity="info">
        <requiresConcept refId="test-impact-analysis:GitBaseCommit" />
        <requiresParameter name="testImpactAnalysisGitBaseBranch" type="String" defaultValue="heads/master"/>
        <description>Adds a label 'Changed' to Git files that changed in the current branch.</description>
        <cypher><![CDATA[
            // Identify base commits reachable from current repository head (i.e. current branch)
            MATCH
              (repository:Repository)-[:HAS_HEAD]->(currentHead:Commit),
              history=shortestPath((base:Commit:Base)<-[:HAS_PARENT*]-(currentHead))
            WHERE
              currentHead <> base
            WITH
              repository, currentHead, base, history
            ORDER BY
              base.epoch desc
            // Find first base commit that is reachable from selected base branch
            MATCH
              (baseBranch:Branch)-[:HAS_HEAD]->(baseHead),
              shortestPath((base)-[:HAS_HEAD|HAS_PARENT*]-(baseBranch))
            WHERE
              baseBranch.name ends with {testImpactAnalysisGitBaseBranch}
              and currentHead <> baseHead
            WITH
              history
            LIMIT
              1
            // Use commits for determining changed files
            UNWIND
              tail(nodes(history)) as commit
            WITH
              commit
            MATCH
              (commit)-[:CONTAINS_CHANGE]->()-[:MODIFIES]->(sourceFile:File)
            SET
              sourceFile:Changed
            RETURN
              commit as Commit, collect(sourceFile.relativePath) as FilesChangedByCommit
        ]]></cypher>
    </concept>

    <concept id="test-impact-analysis:TypesChangedByCurrentGitBranch" severity="info">
        <requiresConcept refId="test-impact-analysis:FilesChangedByCommitsInCurrentGitBranch" />
        <requiresConcept refId="junit4:TestClass" />
        <description>Adds a label 'Changed' to Java types that changed in the current branch.</description>
        <cypher><![CDATA[
            MATCH
              (sourceFile:File:Changed)
            WHERE
              sourceFile.relativePath ends with ".java"
            WITH
              sourceFile
            MATCH
              (package:Package)-[:CONTAINS]->(changedType:Type)
            WHERE
              sourceFile.relativePath ends with (package.fileName + "/" + changedType.sourceFileName)
            SET
              changedType:Changed
            RETURN
              changedType
        ]]></cypher>
    </concept>

    <concept id="test-impact-analysis:TestsAffectedByCurrentGitBranch" severity="info">
        <requiresConcept refId="test-impact-analysis:TypesChangedByCurrentGitBranch" />
        <requiresConcept refId="junit4:TestClass" />
        <description>Adds a label 'Affected' to all test classes having a dependency to Java types which were changed by commits in the current Git branch.</description>
        <cypher><![CDATA[
            MATCH
              hierarchy=shortestPath((changedType:Type:Changed)-[:EXTENDS|IMPLEMENTS*0..]-(type:Type))
            WITH
              type, hierarchy
            WHERE
              all(t in nodes(hierarchy) WHERE (:Artifact)-[:CONTAINS]->(t))
            WITH
              type
            MATCH
              (testArtifact:Artifact)-[:CONTAINS]->(testPackage:Package)-[:CONTAINS]->(test:Test:Class),
              (test)-[:EXTENDS|IMPLEMENTS*0..]->(:Class)-[:DEPENDS_ON*0..1]->(type:Type)
            WHERE NOT
              (exists(test.abstract) and test.abstract)
            SET
              test:Affected
            RETURN
              testArtifact as Artifact, collect(distinct test) as Tests
        ]]></cypher>
    </concept>

    <concept id="test-impact-analysis:SurefireSuiteForCurrentBranch" severity="info">
        <requiresConcept refId="test-impact-analysis:TestsAffectedByCurrentGitBranch" />
        <description>Reports all test classes affected by commits in the current Git branch.</description>
        <cypher><![CDATA[
            MATCH
              (:Maven:Project)-[:CREATES]->(artifact:Artifact)
            OPTIONAL MATCH
              (artifact)-[:CONTAINS]->(test:Affected:Test)
            RETURN
              artifact as Artifact, collect(test) as Tests
        ]]></cypher>
        <report type="surefire-suite" />
    </concept>

    <constraint id="test-impact-analysis:TestGapForLastGitCommit">
        <requiresConcept refId="test-impact-analysis:TypesChangedByLastGitCommit" />
        <requiresConcept refId="junit4:TestMethod" />
        <requiresParameter name="testImpactAnalysisGapMethodVisibility" type="String" defaultValue="public"/>
        <description>Public methods of Java types that changed in the last Git commit which are not covered by test methods (experimental).</description>
        <cypher><![CDATA[
            WITH
              split({testImpactAnalysisGapMethodVisibility},",") as visibilities
            MATCH
              (type:Changed)-[:DECLARES]->(method:Method)
            WHERE
              not method:Constructor
              and method.visibility in visibilities
              and not (:Test:Method)-[:INVOKES]->(method)
            WITH
              type, collect(method) as Methods
            MATCH
              (artifact:Artifact)-[:CONTAINS]->(type)
            RETURN
              artifact as Artifact, type as Type, Methods
        ]]></cypher>
    </constraint>

    <constraint id="test-impact-analysis:TestGapForCurrentGitBranch">
        <requiresConcept refId="test-impact-analysis:TypesChangedByCurrentGitBranch" />
        <requiresConcept refId="junit4:TestMethod" />
        <requiresParameter name="testImpactAnalysisGapMethodVisibility" type="String" defaultValue="public"/>
        <description>Public methods of Java types that changed in the current Git branch which are not covered by test methods (experimental).</description>
        <cypher><![CDATA[
            WITH
              split({testImpactAnalysisGapMethodVisibility},",") as visibilities
            MATCH
              (type:Changed)-[:DECLARES]->(method:Method)
            WHERE
              not method:Constructor
              and method.visibility in visibilities
              and not (:Test:Method)-[:INVOKES]->(method)
            WITH
              type, collect(method) as Methods
            MATCH
              (artifact:Artifact)-[:CONTAINS]->(type)
            RETURN
              artifact as Artifact, type as Type, Methods
        ]]></cypher>
    </constraint>

</jqa:jqassistant-rules>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy