gpt4 book ai didi

unit-testing - Grails 2.1.1-单元测试和模拟域类的元素

转载 作者:行者123 更新时间:2023-12-02 14:17:18 24 4
gpt4 key购买 nike

在为我的项目编写单元测试时,我需要一些帮助。
我已经为 Controller 和域创建了单元测试类。

我的问题是-
我有一个名为employee的域类
它具有-
字串编号
字符串名字
字符串middleInitial
字符串姓氏
字符串状态
字符串empType
字符串用户ID

我想在测试类EmployeeControllerTest()下的setUp()方法中模拟它们

我添加了以下Mixin

package EmployeeController

import static org.junit.Assert.*

import grails.test.mixin.*
import grails.test.mixin.support.*
import org.junit.*
import java.io.Serializable

import grails.test.mixin.TestFor
import grails.test.mixin.TestMixin
import grails.test.mixin.Mock
import grails.test.mixin.support.GrailsUnitTestMixin
import grails.test.mixin.domain.DomainClassUnitTestMixin
import grails.test.mixin.services.ServiceUnitTestMixin
import grails.test.mixin.web.ControllerUnitTestMixin
import grails.test.mixin.web.FiltersUnitTestMixin
import grails.test.mixin.web.GroovyPageUnitTestMixin
import grails.test.mixin.web.UrlMappingsUnitTestMixin
import grails.test.mixin.webflow.WebFlowUnitTestMixin

@TestMixin(GrailsUnitTestMixin)
@TestFor(EmployeeController)
@Mock([Employee])

class EmployeeControllerTests {

void setUp() {
// Setup logic here

def Employee ce = new Employee()
ce.put(empNo: "001", firstname: "amy", middleInitial: "ratr", lastname: "suz", status: "A", empType: "vendor", userid: "amar")
}

void tearDown() {
// Tear down logic here
}

void testSomething() {
//fail "Implement me"
}

请让我知道我是否缺少某些东西或需要进行一些修改。

提前致谢 :)
艾米

最佳答案

您不应该将@TestMixin@TestFor一起使用,因为TestMixin来自grails 1.3中的旧单元测试内容-我建议将其删除

关于unit-testing - Grails 2.1.1-单元测试和模拟域类的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17040848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com