新玩框架和Junit。对java有一点了解。基于play框架入门和文档开始为play应用程序编写单元测试。当我以正常模式运行应用程序时。它适用于数据库模型。
当我在测试模式下运行应用程序时。 显示未找到jpa查询异常和架构。
附上测试类文件供您参考: -
import org.junit.*;
import java.net.*;
import java.util.*;
import play.test.*;
import play.test.FunctionalTest.URL;
import models.*;
import params.*;
public class BasicTest extends UnitTest {
@Test
public void testing(){
//User user = null;
User user = User.find("byUsernameAndPassword","admin","Y29tcGFzczEyMw==").first();
assertNotNull(user);
//assertNotNull("test");
}
}
任何人都可以帮我解决这个问题。
这是我当前的application.conf设置:
db.url=jdbc:vertica://verticadatabaseurlurl/XXXXXXX
db.driver=com.vertica.Driver
db.user=XXXXX
db.pass=XXXXXX
db.schema=XXXXXX
# JPA Configuration (Hibernate)
# ~~~~~
#
# Specify the custom JPA dialect to use here (default to guess):
jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
#
# Specify the ddl generation pattern to use. Set to none to disable it
# (default to update in DEV mode, and none in PROD mode):
jpa.ddl=none
#
# Debug SQL statements (logged using DEBUG level):
jpa.debugSQL=true
#
# You can even specify additional hibernate properties here:
# hibernate.use_sql_comments=true
# ...
#
#%test.module.cobertura=${play.path}/modules/cobertura
%test.application.mode=dev
%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
%test.db=mem
%test.jpa.ddl=create
%test.mail.smtp=mock
我目前正在使用vertica作为数据库。通过此设置可以在正常模式下运行应用程序。在测试模式下,它就会出现这个问题。
http://tinypic.com/r/a48zg4/7 -screenshot参考
答案 0 :(得分:2)
您用于单元测试的JPA配置是什么。更具体,你用于单元测试的persistence.xml是什么。可能需要将架构自动生成配置参数添加到您使用的测试持久性单元,如:
<persistence-unit name="emApplicationManaged_forTests_h2" transaction-type="RESOURCE_LOCAL">
<class>model.Employee</class>
<!-- your Entity classes here -->
<properties>
<!-- your hibernate specific params here -->
<!-- the below parameter tells hibernate to create the schema when you start your app (test) and to erase it when it finishes: -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
以上是针对您使用Hibernate JPA实现的时候。如果您使用Toplink,请尝试:
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="todos" transaction-type="RESOURCE_LOCAL">
<!-- entity classes -->
<properties>
<!-- eclipselink specific config-->
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
</persistence>
对于Play框架,您有一些以test开头的特殊配置参数。字首。试试这个:打开你的application.conf配置文件并添加为db模式自动创建配置测试环境的行:
%test.db=mem
%test.jpa.ddl=create-drop
然后从Play单元测试运行页面(localhost:9090 / @ tests#)
尝试测试另外看看这个Play作弊表,它非常实用(我认为“Multidev Environment”一章与你的具体问题相关):
http://playcheatsheet.appspot.com/show/ArtemMedeu/armed/play-cheatsheets