Grails fixtures插件和功能测试复制数据

Grails fixtures插件和功能测试复制数据,grails,duplicates,integration-testing,functional-testing,fixtures,Grails,Duplicates,Integration Testing,Functional Testing,Fixtures,在BootStrap.groovy中运行fixtureLoader.load时出现问题 import grails.plugin.fixtures.FixtureLoader class BootStrap { def fixtureLoader def init = { servletContext -> environments { test { fixtureL

在BootStrap.groovy中运行fixtureLoader.load时出现问题

import grails.plugin.fixtures.FixtureLoader

class BootStrap {

    def fixtureLoader

    def init = { servletContext ->

            environments {
                test  {

                    fixtureLoader.load {

                        build {
                            device1(Device, name: "device1")
                            device2(Device, name: "device2")
                            device3(Device, name: "device3")
                        }
                    }
                }
            }
        }

    def destroy = {
    }
}
当Grails开始集成测试阶段时,将执行加载。然后,当Grails开始功能测试阶段时,将再次执行负载,而不清理之前的执行

这意味着:

如果我使用“测试应用程序功能:”或“测试应用程序集成:”运行,则一切正常。 如果使用“测试应用程序”运行,则会执行功能测试和集成测试

这是功能测试阶段数据的JSON表示(使用“测试应用程序”运行):

这是功能测试阶段数据的相同JSON表示(使用“test app functional:”运行)

如何避免这种重复


提前感谢

默认测试数据库是一个非持久内存hsqldb,在测试结束时会被丢弃,但对它的更改将在测试阶段之间继续进行。此外,集成测试会在每次测试后回滚更改,但这不适用于在
Bootstrap.groovy
中进行的数据库更改

解决这个问题的一个简单方法是在尝试创建设备之前简单地检查设备是否存在。例如:

environments {
    test {
        if (Device.count() == 0) {
            // build fixtures
        }
     }
 }

另一种可能的解决方案是使用单独的数据库进行集成和功能测试。在

上有一个如何做的示例,非常感谢您的回复。此解决方法可能对我有效:-)
[[name:device3], [name:device2], [name:device1]]
environments {
    test {
        if (Device.count() == 0) {
            // build fixtures
        }
     }
 }