71 lines
2.8 KiB
XML
71 lines
2.8 KiB
XML
<jqa:jqassistant-rules xmlns:jqa="http://www.buschmais.com/jqassistant/core/analysis/rules/schema/v1.0">
|
|
|
|
<constraint id="testrules:TestClassName">
|
|
<requiresConcept refId="junit4:TestClass" />
|
|
<description>All JUnit test classes must have a name that includes "IT", "Test", "Base", or "Demo".</description>
|
|
<cypher><![CDATA[
|
|
MATCH
|
|
(t:Junit4:Test:Class)
|
|
WHERE NOT
|
|
t.name =~ ".*(IT|Test|Base|Demo).*"
|
|
RETURN
|
|
t AS InvalidTestClass
|
|
]]></cypher>
|
|
</constraint>
|
|
|
|
<constraint id="testrules:IgnoredTest">
|
|
<requiresConcept refId="junit4:IgnoreTestClassOrMethod" />
|
|
<description>List all ignored JUnit 4 tests.</description>
|
|
<cypher><![CDATA[
|
|
MATCH
|
|
(method:Method:Ignore)
|
|
RETURN
|
|
method
|
|
]]></cypher>
|
|
</constraint>
|
|
|
|
<concept id="testrules:TestWithExpectedException">
|
|
<requiresConcept refId="junit4:TestMethod" />
|
|
<description>Finds tests with an Expected Exception.</description>
|
|
<cypher><![CDATA[
|
|
MATCH
|
|
(testType:Type)-[:DECLARES]->(testMethod:Test:Method),
|
|
(testMethod)-[:ANNOTATED_BY]->(a)-[:OF_TYPE]->(:Type{fqn:"org.junit.Test"}),
|
|
(a)-[:HAS]->(v:Value{name:"expected"})-[:IS]->(expectedException:Type)
|
|
MERGE
|
|
(testMethod)-[:EXPECTS_EXCEPTION]->(expectedException)
|
|
RETURN
|
|
testType as DeclaringType,
|
|
testMethod as Method,
|
|
expectedException as ExpectedException
|
|
]]></cypher>
|
|
</concept>
|
|
|
|
<constraint id="testrules:TestMethodWithoutAssertion">
|
|
<requiresConcept refId="junit4:TestMethod" />
|
|
<requiresConcept refId="junit4:AssertMethod" />
|
|
<requiresConcept refId="testrules:TestWithExpectedException" />
|
|
<description>Finds tests without an assert.</description>
|
|
<cypher><![CDATA[
|
|
MATCH
|
|
(testType:Type)-[:DECLARES]->(testMethod:Test:Method)
|
|
WHERE NOT (
|
|
(testMethod)-[:ANNOTATED_BY]->(:ANNOTATION)-[:OF_TYPE]->(:TYPE {FQN:"org.junit.Ignore"})
|
|
OR (testMethod)-[:INVOKES*..3]->(:Method:Assert)
|
|
OR (testMethod)-[:EXPECTS_EXCEPTION]->(:Type)
|
|
)
|
|
RETURN
|
|
testType AS DeclaringType,
|
|
testMethod AS Method
|
|
]]></cypher>
|
|
</constraint>
|
|
|
|
<group id="default">
|
|
<includeConstraint refId="testrules:IgnoredTest" severity="minor"/>
|
|
<includeConstraint refId="testrules:TestClassName" />
|
|
<includeConstraint refId="testrules:TestMethodWithoutAssertion" severity="minor" />
|
|
<includeConstraint refId="junit:IgnoreWithoutMessage" />
|
|
</group>
|
|
|
|
</jqa:jqassistant-rules>
|