【问题标题】:How to test mapping for a Grails 3 domain class如何测试 Grails 3 域类的映射
【发布时间】:2017-04-05 00:08:43
【问题描述】:

给定一个域类,例如:

class Person {
    String name

    static mapping = {
        name column: 'TheName'
    }
}

Person 的 name 属性实际上映射到 SQL 表中的 TheName 列。

那么我如何使用 Spock 进行测试,以确保映射存在于域类中?当我创建一个新的 Person 对象时如何访问映射:

new Person(name: 'Anderson')

【问题讨论】:

    标签: testing grails spock


    【解决方案1】:

    我想这就是你所追求的?

    GrailsDomainBinder.getMapping( Person ).getPropertyConfig( 'name' ).columns
    

    会给你类似的东西:

    [column[name:TheName, index:null, unique:false, length:-1, precision:-1, scale:-1]]
    

    【讨论】:

      猜你喜欢
      • 2014-09-06
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      • 2015-10-20
      • 1970-01-01
      相关资源
      最近更新 更多