Grails里的集成测试代码试例
测试的命令,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里的集成测试代码试例的更多相关文章
- [iOS翻译]《iOS7 by Tutorials》在Xcode 5里使用单元測试(上)
简单介绍: 单元測试是软件开发的一个重要方面.毕竟,单元測试能够帮你找到bug和崩溃原因,而程序崩溃是Apple在审查时拒绝app上架的首要原因. 单元測试不是万能的,但Apple把它作为开发工具包的 ...
- C++ 内存模型 write_x_read_y 试例构造
之前一段时间偶然在 B 站上刷到了南京大学蒋炎岩(jyy)老师在直播操作系统网课.点进直播间看了一下发现这个老师实力非凡,上课从不照本宣科,而且旁征博引又不吝于亲自动手演示,于是点了关注.后来开始看其 ...
- 33个超级有用必须要收藏的PHP代码样例
作为一个正常的程序员,会好几种语言是十分正常的,相信大部分程序员也都会编写几句PHP程序,如果是WEB程序员,PHP一定是必备的,即使你没用开发过大型软件项目,也一定多少了解它的语法. 在PHP的流行 ...
- java servlet 代码样例 (demo)
今天又搞了下jsp +servlet 的代码样例,感觉虽然搭了好多次,可是每次还是不记得那些参数,都要去网上搜索,索性自己把这次的简单demo给记录下来,供下次使用的时候直接复制吧. 这个web逻辑 ...
- paip.输入法编程--英文ati化By音标原理与中文atiEn处理流程 python 代码为例
paip.输入法编程--英文ati化By音标原理与中文atiEn处理流程 python 代码为例 #---目标 1. en vs enPHati 2.en vs enPhAtiSmp 3.cn vs ...
- 驱动里执行应用层代码之KeUserModeCallBack(WOW64是由三个动态库wow64.dll wow64win.dll wow64cpu.dll来实现)
在驱动层(ring0)里执行应用层(ring3)代码,这是个老生常谈的技术,而且方法也挺多. 这种技术的本质:其实就是想方设法在驱动层里把应用层代码弄到应用层去执行. 比如在APC异步调用中,KeIn ...
- 在Eclipse里设置格式化代码时不格式化注释
在Eclipse里设置格式化代码时不格式化注释 今天格式化代码 发现直接format会把注释也一块格式化了,有时候会把好好的注释弄的很乱.甚为头疼. 查阅之后解决办法如下: Windows -> ...
- 自己改写了一个图片局部放大的jquery插件页面里面的html代码少了,同一个页面可以调用多个
自己改写了一个图片局部放大的jquery插件页面里面的html代码少了,同一个页面可以调用多个,兼容ie8以上浏览器,别忘了引用jquery,我用的jquery/1.11.0/其他版本没有测试,另外需 ...
- thinkphp从数据库里的html代码显示页面不解析
首先,这个问题不应该出现在这里,因为以前在用ThinkPHP3.1.2的时候,利用富文本编辑器保存文本后,直接从数据库里面取出的数据都能正常显示,改用ThinkPHP3.2.3之后,thinkphp从 ...
随机推荐
- SQL service 自动解决依赖包 验证
依赖关系解决 ============================================================================================= ...
- hibernate基础学习---hierbnate2级缓存
1:开启二级缓存sessionFactory需要安装jar包 2:在实体类配置文件添加(配置二级缓存).我的配置文件是Account.hbm.xml <?xml version="1. ...
- IE下a标签会触发window.onbeforeunload的问题
今天同事发现一个问题,在我做的控件中,点击tab切换的时候,IE上会触发他页面上的onbeforeunload的事件.一开始以为是我控件上事件导致的,但是当我把所有的绑定事件取消以后,问题依然存在.我 ...
- [Swift通天遁地]三、手势与图表-(5)创建带有标题、图例、坐标轴的柱形图表
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- hastable 用法
一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对,其中 ...
- ACM_Ruin of Titanic(简单贪心)
Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...
- python框架之虚拟环境的配置
在开发过程中,往往同一台电脑要开发不同的项目,不同的项目可能需要不同版本的包,为了解决这个问题就引出了虚拟环境. 配置虚拟环境: 1.安装虚拟环境: sudo pip3 install virtual ...
- VC++文件监控 ReadDirectoryChangesW
#include <windows.h> #include <tchar.h> #include <stdio.h> #include <assert.h&g ...
- mysql常用命令介绍
mysql适用于在Internet上存取数据,支持多种平台 1.主键:唯一标识表中每行的这个列,没有主键更新或删除表中的特定行很困难. 2.连接mysql可以用Navicat 要读取数据库中的内容先要 ...
- 安装nodejs6.9x以后,原来在nodejs4.2.x中运行正常的ionic项目出现问题的解决
安装nodejs6.9x以后,原来在nodejs4.2.x中运行正常的程序出现的问题.看错误信息,由于NodeJs版本升级导致的. 到提示的目录下运行:npm rebuild node-sass -g ...