我正在努力跑第一场比赛! 2.1.x应用程序,我总是收到此错误(这是运行test
个案例):
测试models.TestModel.testCreate失败:默认的EbeanServer尚未定义?这通常通过ebean.datasource.default属性设置。否则,它应该通过registerServer()
以编程方式注册
我已经阅读了官方手册,很多SO问题,甚至还有一些博客,我仍然无法弄清楚为什么我会继续这样做。
注意:我在test.conf
中指定this SO question的Build.scala
文件。
以下是test.conf
的内容:
include "application.conf"
application.version=${application.major}.${application.minor}.${application.revision}-TEST
db.default.driver=org.h2.Driver
db.default.jndiName=DefaultDS
db.default.url="jdbc:h2:mem:play;MODE=PostgreSQL;DB_CLOSE_DELAY=-1"
db.default.user=sa
db.default.password=""
ebean.default="models.*"
ebean.datasource.factory=jndi
ebean.datasource.default=DefaultDS
注意: application.conf
中也指定了相同的键,但带有“prod”值。
我错过了什么? 谢谢!
测试用例非常简单。我正在使用基类,从this blog按原样复制粘贴:
public class TestSomeModel extends BaseModelTest {
@Test
public void myModelCreate() {
SomeModel model = new SomeModel();
model.someStringAttribute = "some value";
assertThat(model.id).isNull();
model.save(); // <--- this is the line that gives the error
assertThat(model.id).isPositive();
}
}
......如果有人坚持要看模特班......
@Entity
public class SomeModel extends Model {
@Id
public Long id;
public String someStringAttribute;
}
答案 0 :(得分:3)
在模型
之前添加@Entity<强> @Entity 强> 公共类SomeModel扩展了Model {
答案 1 :(得分:2)
尝试在fakeApplication()
:
import ...
import play.test.Helpers.*;
public class TestSomeModel extends BaseModelTest {
@Test
public void myModelCreate() {
running(fakeApplication(), new Runnable() {
public void run() {
SomeModel model = new SomeModel();
model.someStringAttribute = "some value";
assertThat(model.id).isNull();
model.save();
assertThat(model.id).isPositive();
}
}
}
}