TestMethodWithoutAssertionOrExpectedException
TestMethodWithoutAssertionOrExpectedException
我有以下规则:
[[junit4:C_TestMethodWithoutAssertion]]
.All Unit Tests must either use a expected Exception or call an Assert Method.
[source,cypher,role=constraint,requiresConcepts="junit4:TestClass,junit4:AssertMethod,junit4:TestMethod",severity=blocker]
----
MATCH
(testType:Type)-[:DECLARES]->(testMethod:Test:Method)
-[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT testMethod.abstract
AND NOT (annotation)-[:HAS]->(:Value{name:"expected"})
AND NOT (testMethod)-[:INVOKES*..3]->(:Method:Assert)
RETURN
testType AS DeclaringType,
testMethod AS Method
----
如果我在 neo4j 浏览器中使用它,该规则将完美运行。
但是如果我将它用于 adoc 文件中的报告,我会得到很多 "FalsePositives"。
有没有人有想法。
LG 克里斯
好的,现在我用括号“()”表示 NOT 语句,这样就可以了:
[[junit4:C_TestMethodWithoutAssertion]]
.All Unit Tests must either use a expected Exception or call an Assert Method.
[source,cypher,role=constraint,requiresConcepts="junit4:TestClass,junit4:AssertMethod,junit4:TestMethod",severity=blocker]
----
MATCH
(testType:Type)-[:DECLARES]->(testMethod:Test:Method)
-[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT (testMethod.abstract)
AND NOT ((annotation)-[:HAS]->(:Value{name:"expected"}))
AND NOT ((testMethod)-[:INVOKES*..3]->(:Method:Assert))
RETURN
testType AS DeclaringType,
testMethod AS Method
----
最后一个查询没有 return 结果,因为抽象部分过滤太多。这是一个固定的和稍微重组的版本:
MATCH
(testType:Type)-[:DECLARES]->(testMethod:Test:Method)
-[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT (has(testMethod.abstract) AND testMethod.abstract)
AND NOT (
(annotation)-[:HAS]->(:Value{name:"expected"})
OR (testMethod)-[:INVOKES*..3]->(:Method:Assert)
)
RETURN
testType AS DeclaringType,
testMethod AS Method
我有以下规则:
[[junit4:C_TestMethodWithoutAssertion]]
.All Unit Tests must either use a expected Exception or call an Assert Method.
[source,cypher,role=constraint,requiresConcepts="junit4:TestClass,junit4:AssertMethod,junit4:TestMethod",severity=blocker]
----
MATCH
(testType:Type)-[:DECLARES]->(testMethod:Test:Method)
-[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT testMethod.abstract
AND NOT (annotation)-[:HAS]->(:Value{name:"expected"})
AND NOT (testMethod)-[:INVOKES*..3]->(:Method:Assert)
RETURN
testType AS DeclaringType,
testMethod AS Method
----
如果我在 neo4j 浏览器中使用它,该规则将完美运行。 但是如果我将它用于 adoc 文件中的报告,我会得到很多 "FalsePositives"。 有没有人有想法。
LG 克里斯
好的,现在我用括号“()”表示 NOT 语句,这样就可以了:
[[junit4:C_TestMethodWithoutAssertion]]
.All Unit Tests must either use a expected Exception or call an Assert Method.
[source,cypher,role=constraint,requiresConcepts="junit4:TestClass,junit4:AssertMethod,junit4:TestMethod",severity=blocker]
----
MATCH
(testType:Type)-[:DECLARES]->(testMethod:Test:Method)
-[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT (testMethod.abstract)
AND NOT ((annotation)-[:HAS]->(:Value{name:"expected"}))
AND NOT ((testMethod)-[:INVOKES*..3]->(:Method:Assert))
RETURN
testType AS DeclaringType,
testMethod AS Method
----
最后一个查询没有 return 结果,因为抽象部分过滤太多。这是一个固定的和稍微重组的版本:
MATCH
(testType:Type)-[:DECLARES]->(testMethod:Test:Method)
-[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT (has(testMethod.abstract) AND testMethod.abstract)
AND NOT (
(annotation)-[:HAS]->(:Value{name:"expected"})
OR (testMethod)-[:INVOKES*..3]->(:Method:Assert)
)
RETURN
testType AS DeclaringType,
testMethod AS Method