使用mockConfig在单元测试中模拟配置

11 views
Skip to first unread message

foxgem

unread,
Dec 15, 2009, 3:57:19 AM12/15/09
to groovy-xa
Grails为单元测试提供了很好的支持,提供了大量的mock方法来减轻单元测试的难度和工作。
 
Hubert Klein Ikkink在他的这篇文章中介绍了在单元测试中使用mockConfig来模拟配置:http://mrhaki.blogspot.com/2009/12/grails-goodness-mocking-configuration.html
 
阅读全文请翻墙。重点摘录,mockConfig的代码示例:
 
// File: test/unit/SimpleServiceTests.groovy
import grails.test.*
 
class SimpleServiceTests extends GrailsUnitTestCase {
    def service
   
    protected void setUp() {
        super.setUp()
        service = new SimpleService()
       
        mockConfig('''         <====================================请看这里
            simple {
                greeting = 'Hello'
                text = 'world.'
            }
        ''')
    }
    
    。。。
}
Reply all
Reply to author
Forward
0 new messages