2

我通常在测试代码中使用 Mixins 来跨测试共享实用程序方法。我有一个我写的测试,它有一个@TestFor@Mixin。我看到的行为是,当我有@TestFor注释时,测试看不到我的@Mixin代码,并在执行时给了我一个 MissingMethodException 。当我删除它时,@TestFor它工作正常。下面是我正在尝试做的一个简化示例。

@Mixin(TagLibTestUtils)
@TestFor(ErrorMessageTagLib)
class ErrorMessageTagLibTests {

    @Test
    void stuff() {
        something()
    }
}

class TagLibTestUtils {

    def something() {
        println ">>> HERE"
    }
}

所以我的问题是做@Mixin@TestFor注释不能一起工作?还是我在这里做错了什么?

4

1 回答 1

4

假设您使用的是 Grails 2.0,您应该@TestMixin代替@Mixin.

如果您查看 的来源TestFor,您将看到以下评论:

/**
 * Used to indicate the class under test. Triggers the @TestMixin AST transform for the given artefact type.
 *
 * @author Graeme Rocher
 * @since 2.0
 */
于 2012-02-02T19:35:45.797 回答