Grails 集成测试套件

发布于 2024-09-16 08:25:10 字数 180 浏览 3 评论 0原文

我们有一组依赖于同一组静态数据的集成测试。由于数据量巨大,我们不想针对每个测试级别进行设置。是否可以在开始时设置数据,运行一组测试并在测试结束时回滚数据。

我们实际上想要的是测试套件级别而不是测试用例级别的回滚。我们正在使用 grails 1.3.1,任何指示都会对我们继续进行非常有帮助。提前致谢。

-普拉卡什

We have a set of integration test which depend upon same set of static data. Since the amount of data is huge we dont want to set it up per test level. Is it possible to setup data at the start, run group of test and rollback the data at the end of test.

What we effectively want is the rollback at test suite level rather than test case level. We are using grails 1.3.1, any pointers would be highly helpful for us to proceed. Thanks in advance.

-Prakash

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉黛浅 2024-09-23 08:25:10

对于一个测试用例,您可以使用:

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

还没有尝试过一套测试用例。

我在静态方法中使用 findByName 确实遇到了一些麻烦,不得不求助于保存 id 并使用 get。

我确实尝试了一个套件,但没有高兴,得到一个:没有可运行的方法。

for one test case you could use:

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

haven't tried a suite of test cases (yet).

i did have some trouble using findByName in the static methods and had to resort to saving an id and using get.

i did try rolling up a suite, but no joy, getting a: no runnable methods.

澉约 2024-09-23 08:25:10

您可以通过将测试用例标记为非事务性并自行管理数据、事务和回滚来控制事务/回滚行为。例子:

class SomeTests extends GrailsUnitTestCase {

    static transactional = false
    static boolean testDataGenerated = false

    protected void setUp() {
        if (!testDataGenerated) {
            generateTestData()
            testDataGenerated = true
        }
    }

    void testSomething() {
        ...test...
    }

    void testSomethingTransactionally() {
        DomainObject.withTransaction {
            ...test...
        }
    }

    void testSomethingTransactionallyWithRollback() {
        DomainObject.withTransaction { status ->
            ...test...
            status.setRollbackOnly()
        }
    }
}

You can take control of the transaction/rollback behaviour by marking your test case as non-transactional and managing data, transactions and rollbacks yourself. Example:

class SomeTests extends GrailsUnitTestCase {

    static transactional = false
    static boolean testDataGenerated = false

    protected void setUp() {
        if (!testDataGenerated) {
            generateTestData()
            testDataGenerated = true
        }
    }

    void testSomething() {
        ...test...
    }

    void testSomethingTransactionally() {
        DomainObject.withTransaction {
            ...test...
        }
    }

    void testSomethingTransactionallyWithRollback() {
        DomainObject.withTransaction { status ->
            ...test...
            status.setRollbackOnly()
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文