测试的命令,3和2不一样了,要找找。。

User.groovy

package com.grailsinaction

class User {

    String loginId
    String password
    String homepage
    Date dateCreated

    static constraints = {
      loginId size: 3..20, unique: true, nullable: false

      password size: 6..8, nullable:false
      homepage url: true, nullable: true
    }
}

UserIntegrationSpec.groovy

package com.grailsinaction

import grails.test.mixin.integration.Integration
import grails.transaction.*
import spock.lang.*

@Integration
@Rollback
class UserIntegrationSpec extends Specification {

    def setup() {
    }

    def cleanup() {
    }

    def "Saving our first user to the database"() {
            given: "A brand new user"
            def joe = new User(loginId: 'Joe', password: 'secret',
                                homepage: 'http://www.grailsinaction.com')
            when: "the user is saved"
            joe.save()

            then: "it saved successfully and can be found in the database"
            joe.errors.errorCount == 0
            joe.id != null
            User.get(joe.id).loginId == joe.loginId
        }

        def "Updating a saved user changes its properties"() {
            given: "An existing user"
            def existingUser = new User(loginId: 'Joe', password: 'secret',
                                homepage: 'http://www.grailsinaction.com')
            existingUser.save(failOnError: true)
            when: "A property is changed"
            def foundUser = User.get(existingUser.id)
            foundUser.password = 'sesame'
            foundUser.save(failOnError: true)

            then: "The change is reflected in the database"
            User.get(existingUser.id).password == 'sesame'
        }

        def "Deleting an existing user removes it from the database"() {
            given: "An existing user"
            def user = new User(loginId: 'Joe', password: 'secret',
                                homepage: 'http://www.grailsinaction.com')
            user.save(failOnError: true)

            when: "The user is deleted"
            def foundUser = User.get(user.id)
            foundUser.delete(flush: true)

            then: "The user is removed from the database"
            !User.exists(foundUser.id)
        }

        def "Saving a user with invalid properties causes an error"() {
            given: "A user which fails several field validations"
            def user = new User(loginId: 'Joe', password: 'tiny',
                                    homepage: 'not-a-url')
            when: "The user is validated"
            user.validate()

            then:
            user.hasErrors()

            "size.toosmall" == user.errors.getFieldError("password").code
            "tiny" == user.errors.getFieldError("password").rejectedValue
            "url.invalid" == user.errors.getFieldError("homepage").code
            "not-a-url" == user.errors.getFieldError("homepage").rejectedValue
            !user.errors.getFieldError("loginId")
        }

        def "Recovering from a failed save by fixing invalid properties"() {
            given: "A user that has invalid properties"
            def chuck = new User(loginId: 'chuck', password: 'tiny',
                                    homepage: 'not-a-url')
            assert chuck.save() == null
            assert chuck.hasErrors()

            when: "We fix the invalid properties"
            chuck.password = "fistfist"
            chuck.homepage = "http://www.chucknorrisfacts.com"
            chuck.validate()

            then: "The user saves and validates fine"
            !chuck.hasErrors()
            chuck.save()
        }

}

Grails里的集成测试代码试例的更多相关文章

  1. [iOS翻译]《iOS7 by Tutorials》在Xcode 5里使用单元測试(上)

    简单介绍: 单元測试是软件开发的一个重要方面.毕竟,单元測试能够帮你找到bug和崩溃原因,而程序崩溃是Apple在审查时拒绝app上架的首要原因. 单元測试不是万能的,但Apple把它作为开发工具包的 ...

  2. C++ 内存模型 write_x_read_y 试例构造

    之前一段时间偶然在 B 站上刷到了南京大学蒋炎岩(jyy)老师在直播操作系统网课.点进直播间看了一下发现这个老师实力非凡,上课从不照本宣科,而且旁征博引又不吝于亲自动手演示,于是点了关注.后来开始看其 ...

  3. 33个超级有用必须要收藏的PHP代码样例

    作为一个正常的程序员,会好几种语言是十分正常的,相信大部分程序员也都会编写几句PHP程序,如果是WEB程序员,PHP一定是必备的,即使你没用开发过大型软件项目,也一定多少了解它的语法. 在PHP的流行 ...

  4. java servlet 代码样例 (demo)

    今天又搞了下jsp +servlet 的代码样例,感觉虽然搭了好多次,可是每次还是不记得那些参数,都要去网上搜索,索性自己把这次的简单demo给记录下来,供下次使用的时候直接复制吧. 这个web逻辑 ...

  5. paip.输入法编程--英文ati化By音标原理与中文atiEn处理流程 python 代码为例

    paip.输入法编程--英文ati化By音标原理与中文atiEn处理流程 python 代码为例 #---目标 1. en vs enPHati 2.en vs enPhAtiSmp 3.cn vs ...

  6. 驱动里执行应用层代码之KeUserModeCallBack(WOW64是由三个动态库wow64.dll wow64win.dll wow64cpu.dll来实现)

    在驱动层(ring0)里执行应用层(ring3)代码,这是个老生常谈的技术,而且方法也挺多. 这种技术的本质:其实就是想方设法在驱动层里把应用层代码弄到应用层去执行. 比如在APC异步调用中,KeIn ...

  7. 在Eclipse里设置格式化代码时不格式化注释

    在Eclipse里设置格式化代码时不格式化注释 今天格式化代码 发现直接format会把注释也一块格式化了,有时候会把好好的注释弄的很乱.甚为头疼. 查阅之后解决办法如下: Windows -> ...

  8. 自己改写了一个图片局部放大的jquery插件页面里面的html代码少了,同一个页面可以调用多个

    自己改写了一个图片局部放大的jquery插件页面里面的html代码少了,同一个页面可以调用多个,兼容ie8以上浏览器,别忘了引用jquery,我用的jquery/1.11.0/其他版本没有测试,另外需 ...

  9. thinkphp从数据库里的html代码显示页面不解析

    首先,这个问题不应该出现在这里,因为以前在用ThinkPHP3.1.2的时候,利用富文本编辑器保存文本后,直接从数据库里面取出的数据都能正常显示,改用ThinkPHP3.2.3之后,thinkphp从 ...

随机推荐

  1. CSS盒子居中的常用的几种方法

    第一种: 用css的position属性 <style type="text/css"> .div1 { width: 100px; height: 100px; bo ...

  2. 对腾讯云服务器linux系统进行分区格式化操作

  3. 拼接html 的事件转义

    attach += "<div style='line-height: 10px;float: left;margin-left: 10px;' id='attach_" + ...

  4. $stylus美化$

    一直在用洛谷 当然不一定是洛谷 其他的网站也可以用 比如说codeforces 还是决定要美化一波 首先去找一个插件 叫做 stylus stylus下载的很多 我不想过多说明. Google和QQ浏 ...

  5. ASP.NET MVC5 之 AspNetUsers 表增加字段

    MVC5 执行数据库迁移时,会生成一些默认的数据表,但是在实际的工作中.若用到的时候,难免要增添一些字段. 1.AspNetUsers 增加字段 A.打开MVC中的 IdentityModels.cs ...

  6. favourite和favorite的区别

    同一个词,英式和美式的拼写法而已.通常英式英语里的-our-字母组合,到了美式英语里面都成了-or-字母组合,最常见的有英式的 colour,到美式英语成了 color.

  7. 【转】Java 集合系列02之 Collection架构

    概要 首先,我们对Collection进行说明.下面先看看Collection的一些框架类的关系图: Collection是一个接口,它主要的两个分支是:List 和 Set. List和Set都是接 ...

  8. bootstrap图标乱码问题-解决方案

    楼主在使用bootstrap时,出现了图标乱码问题,经过多次查找,才解决了问题(最后发现真的是很好解决的问题(^^)) 如果出现乱码 请直接在自己写的CSS中重新引入一下font文件中的字体就好了 @ ...

  9. 增加删除div

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...

  10. Leetcode0523--Continuous Subarray Sum 连续和倍数

    [转载请注明]https://www.cnblogs.com/igoslly/p/9341666.html class Solution { public: bool checkSubarraySum ...