【问题标题】:grails cobertura findAllBygrails cobertura findAllBy
【发布时间】:2019-03-13 22:37:25
【问题描述】:

我有 grails 2.4.4 和 Cobertura 作为隐蔽测试。 我有这样的代码:

lstPerspectives = Perspectives.findAllByDbAndSysDelete(dbInstance, new Long(0)) 

但是 Cobertura 没有通过测试,因为没有在我的数据库中搜索,我怎样才能通过这一行?,如何覆盖这个值?我发送了这个 lstPerspectives 但它不接受它。

谢谢

谢谢

【问题讨论】:

  • 您是否在测试开始时使用给定的dbsysDeletePerspectives 添加到数据库中,可能是在spock 设置或给定块中?
  • 我在 @Mock 中添加了 Perspectives。够了吗?
  • 这取决于你的要求,我将在下面添加一个示例..

标签: grails automated-tests cobertura findall


【解决方案1】:

尝试以下方法:

import grails.test.mixin.Mock
import grails.test.mixin.TestFor

@TestFor(Perspectives)
@Mock([Perspectives])
class PerspectivesSpec 
{
    void "test Perspectives"(){
        given:
            def dbInstance = 'aDbInstance' // don't know what this is
            def sysDelete = false // is this a boolean?
            new Perspectives( dbInstance: dbInstance, sysDelete: sysDelete ).save( failOnError: true )
        when:
            // run you bit of code that executes the snippet in your question
        then:
             // check your desired outcome
    }
}

我不知道你是直接在这里测试你的 Perspectives 类还是其他东西,控制器,服务?所以不得不做一些假设。

【讨论】:

  • 谢谢,但问题仍然存在。我使用 "perspectives.Save(flush:true)" 或仅使用 .save() ,但它说:已连接到目标 VM,地址:127.0.'.......',传输:'socket ' groovy.lang.MissingMethodException: No signature of method: com.snt............Save() 适用于参数类型:() 值:[] 可能的解决方案:save()、save (boolean), save(java.util.Map), wait(), last(), any() at PerspectiveController.Test 保存操作返回正确的模型(PerspectiveController.groovy:227) WARN 警告,无法取消绑定会话,有没有注册 SessionHolder
  • 真的需要查看您的整个测试/项目,您可以在 github 中提供它吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-06
相关资源
最近更新 更多