【问题标题】:Mock-service and Grails jaxrs integration test模拟服务和 Grails jaxrs 集成测试
【发布时间】:2014-04-01 12:32:40
【问题描述】:

我想测试一个 grails 应用程序(使用 jaxrs)和它的集成。对于这个任务,我希望使用 jaxrs 插件中很棒的 IntegrationTestCase 类。 这很有挑战性,因为我想在我的应用程序中模拟/替换服务。使用“纯”Spring,我将创建 testcontext 并手动连接模拟。我不知道如何在 grails 中做到这一点。 我尝试直接访问 ApplicationContext

Holders.grailsApplication.mainContext.registerMockBean("myService", new MyMock())

这似乎不起作用,因为在测试期间未使用模拟。有什么想法吗?

【问题讨论】:

    标签: spring grails groovy jax-rs integration-testing


    【解决方案1】:

    尝试在测试类中定义他的方式:

        @Before
        void before() {
            Holders.grailsApplication = grailsApplication
    
            defineBeans {
                myService(MyMock)
            }
        }
    

    它用于 jUnit 测试。如果您使用 Spock,请将 before() 重命名为 setup() 并查看 Spock basics Fixture Methods。

    【讨论】:

    • 谢谢,但我认为不能将 IntegrationTestCase 与 defineBeans-closure 结合起来。
    • 那你真的需要集成测试吗?
    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多