(Quick Reference)

1.1.5 测试特性 - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith

Version: null

1.1.5 测试特性

New Unit Testing Console Output

Test output from the test-app command has been improved:

新的单元测试输出结果

运行test-app命令的输出结果已经提升为如下图所示:

New Unit Testing API

There is a new unit testing API based on mixins that supports JUnit 3, 4 and Spock style tests (with Spock 0.6 and above). Example:

import grails.test.mixin.TestFor

@TestFor(SimpleController) class SimpleControllerTests { void testIndex() { controller.home()

assert view == "/simple/homePage" assert model.title == "Hello World" } }

The documentation on testing has also been re-written around this new framework.

新的单元测试API

新的单元测试API现在支持JUnit 3, 4和Spock风格(Spock 0.6以上)的测试了,比如:

import grails.test.mixin.TestFor

@TestFor(SimpleController) class SimpleControllerTests { void testIndex() { controller.home()

assert view == "/simple/homePage" assert model.title == "Hello World" } }

本文档中的测试部分也基于此框架进行了重写。

Unit Testing GORM

A new in-memory GORM implementation is present that supports many more features of the GORM API making unit testing of criteria queries, named queries and other previously unsupported methods possible.

GORM的单元测试

在单元测试方面,新的基于内存的GORM实现,使得GORM在条件查询、命名查询以及以前并未支持的方法也得到了很好的支持。

Faster Unit Testing with Interactive Mode

The new interactive mode (activated by typing 'grails') greatly improves the execution time of running unit and integration tests.

交互模式下更快的单元测试

新的交互模式(通过输入'grails'命令激活)极大的缩短了单元和集成测试的运行时间。

Unit Test Scaffolding

A unit test is now generated for scaffolded controllers

脚手架(Scaffolding)的单元测试

使用脚手架的控制器现在也自动生成一个单元测试。