Grails 2.0集成测试有污染吗?

发布于 2024-12-28 10:39:14 字数 1990 浏览 1 评论 0原文

所以我有一个小型集成测试,总共包含 5 个测试。专门运行该测试会导致所有测试都通过。然而,运行我的整个测试套件会导致 5 次测试失败,其中 4 次失败。

我最近刚刚从 1.3.7 升级到 grails-2.0,并从 hsqldb 切换到 h2。

有没有人指出我应该朝哪个方向寻找以解决这个(测试污染)问题?

域模型

domain-model

集成测试:

class SeriesIntegrationTests extends GrailsUnitTestCase {
    Series series
    Episode episode

    protected void setUp() {
        super.setUp()
        series = new Series(ttdbId: 2348);
        episode = new Episode(ttdbId: 2983, season: 0, episodeNumber: 0, series: series);
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testCreateSeries() {
        series.save()
        assertFalse("should not have validation errors : $series.errors", series.hasErrors())
        assertEquals("should be one series stored in db", 1, Series.count())
    }

    void testCreateEpisode() {
        series.save()
        episode.save()
        assertFalse("should not have validation errors : $episode.errors", episode.hasErrors())
        assertEquals("should be one episode stored in db", 1, Episode.count())
    }

    void testCreateSeriesAndAddEpisode() {
        series.addToEpisodes(episode)
        series.save(flush: true)
        series.refresh()
        assertEquals("series should contain one episode", 1, series.episodes.size())
    }

    void testDeleteSeriesAndCascadeToEpisode() {
        series.addToEpisodes(episode)
        series.save(flush: true)
        series.delete(flush: true)
        assertEquals(0, Episode.count())
        assertEquals(0, Series.count())

    }

    void testDeleteSeriesAndCascadeToBackdropImage() {
        series.backdrop = new Image();
        series.backdrop.binaryData = new byte[0]
        series.save(flush: true)

        assertFalse(series.hasErrors())
        assertEquals(1, Image.count())

        series.delete(flush: true)
        assertEquals(0, Image.count())
    }
}

So i have a small integration test that houses 5 tests in total. Running that test exclusively results in all tests passed. However running my entire test suite results in 4 test failures of the 5.

I've just recently upgraded to grails-2.0 from 1.3.7 and i switched from hsqldb to h2.

Has anyone any pointers in which direction i should be looking in order to fix this (test-pollution) problem?

Domain model

domain-model

Integration test:

class SeriesIntegrationTests extends GrailsUnitTestCase {
    Series series
    Episode episode

    protected void setUp() {
        super.setUp()
        series = new Series(ttdbId: 2348);
        episode = new Episode(ttdbId: 2983, season: 0, episodeNumber: 0, series: series);
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testCreateSeries() {
        series.save()
        assertFalse("should not have validation errors : $series.errors", series.hasErrors())
        assertEquals("should be one series stored in db", 1, Series.count())
    }

    void testCreateEpisode() {
        series.save()
        episode.save()
        assertFalse("should not have validation errors : $episode.errors", episode.hasErrors())
        assertEquals("should be one episode stored in db", 1, Episode.count())
    }

    void testCreateSeriesAndAddEpisode() {
        series.addToEpisodes(episode)
        series.save(flush: true)
        series.refresh()
        assertEquals("series should contain one episode", 1, series.episodes.size())
    }

    void testDeleteSeriesAndCascadeToEpisode() {
        series.addToEpisodes(episode)
        series.save(flush: true)
        series.delete(flush: true)
        assertEquals(0, Episode.count())
        assertEquals(0, Series.count())

    }

    void testDeleteSeriesAndCascadeToBackdropImage() {
        series.backdrop = new Image();
        series.backdrop.binaryData = new byte[0]
        series.save(flush: true)

        assertFalse(series.hasErrors())
        assertEquals(1, Image.count())

        series.delete(flush: true)
        assertEquals(0, Image.count())
    }
}

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

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

发布评论

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

评论(2

桃扇骨 2025-01-04 10:39:14

从 1.3.7 迁移到 2.0 时,我遇到了类似的问题。集成测试在启动时没问题

grails test-app --integration

,但在启动时失败

grails test-app

我通过将单元测试转换为 grails 2.0 测试(使用注释)修复了所有问题。

I had a similar problem when moving from 1.3.7 to 2.0. The integration tests were ok when launched with

grails test-app --integration

but were failing when launched with

grails test-app

I fixed everything by converting unit tests to grails 2.0 test (using annotations).

恬淡成诗 2025-01-04 10:39:14

我的解决方案是将所有单元测试升级为 grails 2.0 的测试方法。完成后,所有测试都通过了。所以看起来单元测试在某种程度上污染了集成测试。但仅限于某些硬件配置。

My solution as to upgrade all the unit tests to grails 2.0 method of doing tests. When this was done, every test passed. So it seem's that unit tests somehow polluted integration tests. But only on certain hardware configurations.

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