I moved my enum in src\groovy folder and it fix the problem.
Grails - Cannot unit test a enum located in domain package/folder
-
31-05-2022 - |
题
I have a enum
public enum Foo {
FOO1(true)
FOO2(false)
FOO3(true)
boolean respectACondition
Foo(boolean isRespecting) {
respectAContidion = isRespecting
}
boolean isRespecting() {
this.respectACondition
}
}
And a test class
class FooTests {
@Test
void test() {
assert Foo.FOO1.isRespecting()
assert !Foo.FOO2.isRespecting()
assert Foo.FOO3.isRespecting()
}
}
But I got this error:
org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Cannot add Domain class [class Foo]. It is not a Domain!
It seem that grails run a automatic background GrailsUnitTestMixin on the Foo class by deducting it by the class name. If I renamed it, it works (but it's too simple, I wanna know what's the problem) What do I do wrong? Do I need to put my enum outside of the domain directory?
解决方案
不隶属于 StackOverflow