Grails 为什么域类在同一GroovyTestCase的两个不同方法中表现不同?

Grails 为什么域类在同一GroovyTestCase的两个不同方法中表现不同?,grails,groovy,integration-testing,Grails,Groovy,Integration Testing,我有一个Grails集成测试,它通过两种测试方法进行扩展。第一个方法成功执行,但第二个方法失败,出现groovy.lang.MissingMethodException: 失败:testMapBudgetFailure(com.ross.budget.BudgetServiceTests) groovy.lang.MissingMethodException:没有方法的签名: com.ross.budget.budget.save()适用于参数类型:()值:[] 可能的解决方案:save()、s

我有一个Grails集成测试,它通过两种测试方法进行扩展。第一个方法成功执行,但第二个方法失败,出现
groovy.lang.MissingMethodException

失败:testMapBudgetFailure(com.ross.budget.BudgetServiceTests)
groovy.lang.MissingMethodException:没有方法的签名:
com.ross.budget.budget.save()适用于参数类型:()值:[] 可能的解决方案:save()、save(布尔)、save(java.util.Map)、wait()、last()、any()
在 testMapBudgetFailure(BudgetServiceTests.groovy:45)

即使在第一个方法中调用了完全相同的方法
b.save()
。如果我对第一个方法进行注释,第二个测试将按预期运行为什么这两种测试方法表现不同?

完整类列表:

package com.ross.budget



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
 */
@TestFor(BudgetService)
class BudgetServiceTests extends GroovyTestCase {


    BudgetService budgetService

    void testMapBudgetSuccess() {
        Budget b = new Budget()
        b.month = new Date(2012, 9, 1)
        b.amount = new BigDecimal(10.0)
        b.save()

        Account a = new Account()
        a.name = "Test"
        a.institution = "Test"
        a.description = "Test Account"
        a.save()

        Transaction t = new Transaction()
        t.account = a
        t.postDate = new Date(2012, 9, 5)
        t.amount = 10.0
        t.save()

        boolean result = budgetService.mapTransaction(t)
        assertTrue("Returned failed match.", result)
        assertNotNull("No budget set", t.budget)

    }

    void testMapBudgetFailure() {
        Budget b = new Budget()
        b.month = new Date(112, 5, 1)
        b.amount = new BigDecimal(10.0)
        b.save()

        Account a = new Account()
        a.name = "Test"
        a.institution = "Test"
        a.description = "Test Account"
        a.save()

        Transaction t = new Transaction()
        t.account = a
        t.postDate = new Date(112, 6, 5)
        t.amount = 10.0
        t.save()

        boolean result = budgetService.mapTransaction(t)
        assertFalse("Returned match.", result)
        assertNull("Budget set", t.budget)

    }
}

我知道代码是复制粘贴的,不可爱。它是个人项目的快速测试用例

根据,您应该使用
@TestFor
进行单元测试,或者扩展
GroovyTestCase
进行集成测试,而不是两者都使用。

据我从文档中了解,您应该使用
@TestFor
或者从
GroovyTestCase
进行扩展,这并不奇怪,你能发布域类的代码吗?如果你删除了有效的
@TestFor(…)
注释?@denis.solonenko,它能工作吗。你能把它贴出来作为答复吗,我会接受的。