【发布时间】:2017-05-17 06:30:50
【问题描述】:
目前正在搜索教程、解释和示例。 我尝试了不同的示例并提出了不同的错误。 我目前的错误是:
| Error Compilation error compile [unit] tests: startup failed:
在我的测试报告中。它输出这个:
单元测试结果 - 总结 未执行任何测试。
我的“UserSpec.groovy”代码是这样的:
package newmyproject245
import grails.test.mixin.*
import spock.lang.Specification
@TestFor(User)
class UserSpec extends ConstraintSpecification {
def setup() {
Expectations.applyTo User
}
def cleanup() {
}
void testShouldDoNothing() {
Expectations.applyTo User
user."password is not blank"
user."password is not nullable"
user."name is not blank"
user."name is not nullable"
}
void testEventNameConstraints() {
Expectations.applyTo User
def user = new User()
user."name is not blank"
user."name is not nullable"
}
}
谁能帮忙。我是grails的新手。 谢谢!
除了上述问题, 当我省略了类中的 Contraints 时:
class UserSpec extends Specification {
我遇到了这个错误:
|运行 1 个单元测试... 1 of 1 |失败:initializationError(org.junit.runner.manipulation.Filter) | java.lang.Exception:没有找到匹配 grails 测试目标的测试 来自 org.junit.runner.Request$1@12c27788 的模式过滤器 在 org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35) 在 org.junit.runner.JUnitCore.run(JUnitCore.java:138) | 0m 0s完成1个单元测试,1个失败 |错误致命错误运行测试:非空属性引用瞬态值 - 瞬态实例必须在当前操作之前保存:newmyproject245.Order.product -> newmyproject245.Product;嵌套异常是 org.hibernate.TransientPropertyValueException: Not-null property references a transient value - 在当前操作之前必须保存瞬态实例:newmyproject245.Order.product -> newmyproject245.Product(使用 --stacktrace 查看完整跟踪)
有人帮忙。再次感谢!
【问题讨论】:
标签: unit-testing grails groovy