Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing Grails2.0:如何在单元测试中正确使用模拟_Unit Testing_Grails - Fatal编程技术网

Unit testing Grails2.0:如何在单元测试中正确使用模拟

Unit testing Grails2.0:如何在单元测试中正确使用模拟,unit-testing,grails,Unit Testing,Grails,我是否必须将域类保存到模拟表中,如2.0中所示: def jdoe = new User(name:"John Doe", role:"user") def suziq = new User(name:"Suzi Q", role:"admin") def jsmith = new User(name:"Jane Smith", role:"user") mockDomain(User, [jdoe, suziq, jsmith]) def test = User.get(1) //corr

我是否必须将域类保存到模拟表中,如2.0中所示:

def jdoe = new User(name:"John Doe", role:"user")
def suziq = new User(name:"Suzi Q", role:"admin")
def jsmith = new User(name:"Jane Smith", role:"user")

mockDomain(User, [jdoe, suziq, jsmith])

def test = User.get(1) //correct ?
或者仅仅使用@Mock和@TestFor就足够了

@TestFor(MyController)
@Mock([User,Role])
{...

def jdoe = new User(name:"John Doe", role:"user")
def suziq = new User(name:"Suzi Q", role:"admin")
def jsmith = new User(name:"Jane Smith", role:"user")

def test = User.get(1) //will this work ?
}

使用
@Mock
的第二次尝试应该会成功。

使用
@Mock
的第二次尝试应该会成功。

在域对象和混合的单元测试中使用刷新

@TestFor(MyController)
@Mock([User,Role])
@TestMixin(DomainClassUnitTestMixin)
{...

    def jdoe = new User(name:"John Doe", role:"user").save(flush:true)
    def suziq = new User(name:"Suzi Q", role:"admin").save(flush:true)
    def jsmith = new User(name:"Jane Smith", role:"user").save(flush:true)

    def test = User.get(1) //will this work ?
}

在域对象和mixin的单元测试中使用flushing

@TestFor(MyController)
@Mock([User,Role])
@TestMixin(DomainClassUnitTestMixin)
{...

    def jdoe = new User(name:"John Doe", role:"user").save(flush:true)
    def suziq = new User(name:"Suzi Q", role:"admin").save(flush:true)
    def jsmith = new User(name:"Jane Smith", role:"user").save(flush:true)

    def test = User.get(1) //will this work ?
}

可以应用于测试类到另一个类的mixin行为的AST转换可以应用于测试类到另一个类的mixin行为的AST转换