Skip to content

Commit 4e5fca7

Browse files
authored
Improve testing framework (#325)
- split up parsing asciidoc and test case generation - allow hierarchical lookup for setup code
1 parent f2f96aa commit 4e5fca7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+695
-528
lines changed

.run/Reformat Tests.run.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Reformat Tests" type="JUnit" factoryName="JUnit">
3+
<module name="neo4j-graphql-java"/>
4+
<option name="MAIN_CLASS_NAME" value=""/>
5+
<option name="METHOD_NAME" value=""/>
6+
<option name="TEST_OBJECT" value="directory"/>
7+
<option name="VM_PARAMETERS" value="-ea -Dneo4j-graphql-java.reformat=true"/>
8+
<dir value="$PROJECT_DIR$/core/src/test/kotlin/org/neo4j/graphql"/>
9+
<method v="2">
10+
<option name="Make" enabled="true"/>
11+
</method>
12+
</configuration>
13+
</component>
Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
11
package org.neo4j.graphql
22

3+
import demo.org.neo4j.graphql.utils.asciidoc.ast.CodeBlock
4+
import demo.org.neo4j.graphql.utils.asciidoc.ast.Section
35
import org.junit.jupiter.api.Assertions
46
import org.junit.jupiter.api.DynamicNode
57
import org.junit.jupiter.api.DynamicTest
68
import org.junit.jupiter.api.TestFactory
79
import org.neo4j.graphql.utils.AsciiDocTestSuite
810
import java.util.stream.Stream
911

10-
class TranslatorExceptionTests : AsciiDocTestSuite("translator-tests1.adoc") {
12+
class TranslatorExceptionTests : AsciiDocTestSuite<CodeBlock>("translator-tests1.adoc", emptyList()) {
1113

12-
@TestFactory
13-
fun createTests(): Stream<DynamicNode> {
14-
return generateTests()
14+
override fun createTestCase(section: Section): CodeBlock? {
15+
return findSetupCodeBlocks(section, "graphql", mapOf("schema" to "true")).firstOrNull() ?: return null
1516
}
1617

17-
override fun schemaTestFactory(schema: String): List<DynamicNode> {
18-
val translator = Translator(SchemaBuilder.buildSchema(schema))
18+
override fun createTests(testCase: CodeBlock, section: Section, ignoreReason: String?): List<DynamicNode> {
19+
if (section.title != "Tests") {
20+
return emptyList()
21+
}
1922
return listOf(
2023
DynamicTest.dynamicTest("unknownType") {
2124
Assertions.assertThrows(InvalidQueryException::class.java) {
22-
translator.translate(
23-
"""
24-
{
25-
company {
26-
name
27-
}
28-
}
25+
Translator(SchemaBuilder.buildSchema(testCase.content)).translate(
2926
"""
27+
{
28+
company {
29+
name
30+
}
31+
}
32+
"""
3033
)
3134
}
3235
},
3336
DynamicTest.dynamicTest("mutation") {
3437
Assertions.assertThrows(InvalidQueryException::class.java) {
35-
translator.translate(
38+
Translator(SchemaBuilder.buildSchema(testCase.content)).translate(
3639
"""
37-
{
38-
createPerson()
39-
}
40-
""".trimIndent()
40+
{
41+
createPerson()
42+
}
43+
""".trimIndent()
4144
)
4245
}
4346
}
44-
4547
)
4648
}
49+
50+
@TestFactory
51+
fun createTests(): Stream<DynamicNode> = generateTests()
4752
}

0 commit comments

Comments
 (0)