Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Specs2/Neo4j-将非永久图形数据库与Specs2一起使用_Neo4j_Spring Data Neo4j_Specs2 - Fatal编程技术网

Specs2/Neo4j-将非永久图形数据库与Specs2一起使用

Specs2/Neo4j-将非永久图形数据库与Specs2一起使用,neo4j,spring-data-neo4j,specs2,Neo4j,Spring Data Neo4j,Specs2,我正在使用Specs2编写验收测试 我想使用非永久图形数据库来创建内存中的Neo4j图形;非常适合集成测试 我为Neo4j设置了Spring数据,我的Spring文件配置包含: <bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/> 我想知道Specs2是否考虑了选项destroy method=“shutdown”,而

我正在使用Specs2编写验收测试

我想使用
非永久图形数据库
来创建内存中的Neo4j图形;非常适合集成测试

我为Neo4j设置了Spring数据,我的Spring文件配置包含:

<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>

我想知道Specs2是否考虑了选项
destroy method=“shutdown”
,而不是通常的
JUnit
,以便隔离每个Spec的
示例

总而言之:每个
示例是否都有自己的内存中图形实例,或者共享给所有示例?

我猜它不适用,因为specs2使用相同的
规范
实例来执行所有这些Spec的示例。事实上,对于Specs2的函数样式,只有
is()
方法被称为在一个实例中嵌入所有示例

我还试图实现
BeforeExample
特性,以便在每个
示例中清理数据库,但是。。。对于给定的/Then/When样式,似乎整体被视为一个独特的
示例
。实际上,分隔符是
^
,而不是传统的
,后者表示一个
示例


我想在每个步骤之前(
给定的
然后
步骤)清理内存中的数据库(
非永久图数据表)

我对您的问题的理解是,在每组给定的/When/Then步骤之前,您需要一个“新的”数据库

为此,您可以:

  • 在每组给定的/When/Then步骤之前明确指定操作

    Step(cleanupDatabase) ^
    "A given-when-then example for the addition" ^
      "Given the following number: ${1}"         ^ number1 ^
      "And a second number: ${2}"                ^ number2 ^
      "And a third number: ${3}"                 ^ number3 ^
                                                 end^
    Step(cleanupDatabase) ^
    "A given-when-then example for the addition" ^
     "Given the following number: ${1}"         ^ number1 ^
     "And a second number: ${2}"                ^ number2 ^
     "And a third number: ${3}"                 ^ number3 ^
                                             end
    
  • 使用函数声明每个组,并在每个组之前映射清理步骤

    def `first example` =     
      "A given-when-then example for the addition" ^
        "Given the following number: ${1}"         ^ number1 ^
        "And a second number: ${2}"                ^ number2 ^
        "And a third number: ${3}"                 ^ number3 ^
                                                   end
    def `second example` =     
      "A given-when-then example for the addition" ^
        "Given the following number: ${1}"         ^ number1 ^
        "And a second number: ${2}"                ^ number2 ^
        "And a third number: ${3}"                 ^ number3 ^
                                                   end
    
    def is = Seq(`first example`, `second example`).foldLeft(Step():Fragments) { (res, cur) =>
      res ^ Step(cleanupDatabase) ^ cur 
    }
    
  • 通常使用

    override def map(fs: =>Fragments) = fs.flatMap {
      // clean the database at the end of a G/W/T block
      case f if f == end => Seq(Step(cleanDatabase), end)
      case other         => Seq(other)    
    }
    

我喜欢最后一个建议,但是
End()
是一个无法访问的
案例类
(因为它的englobing对象用
private[specs2]
注释)。对了,我删除了这个限制,但也检查了我之前没有编译的答案!我将对答案进行编辑,并使用最新的1.12.4-SNAPSHOT使其变得更好。