У меня есть следующий класс домена с производным свойством lowercaseTag
.
class Hashtag {
String tag
String lowercaseTag
static mapping = {
lowercaseTag formula: 'lower(tag)'
}
}
Если я запущу следующий модульный тест, он завершится ошибкой в последней строке, потому что свойство lowercaseTag
равно null
, а по умолчанию все свойства имеют ограничение nullable: false
.
@TestFor(Hashtag)
class HashtagSpec extends Specification {
void "Test that hashtag can not be null"() {
when: 'the hashtag is null'
def p = new Hashtag(tag: null)
then: 'validation should fail'
!p.validate()
when: 'the hashtag is not null'
p = new Hashtag(tag: 'notNullHashtag')
then: 'validation should pass'
p.validate()
}
}
Вопрос в том, как правильно писать юнит-тесты в таких случаях? Спасибо!
lowercaseTag
, а формула определяется для несуществующего свойстваlowercase
? - person Emmanuel Rosa   schedule 22.01.2016