运行jtest出现 No value found for property database.type 错误解决办法

错误信息:
Caused by: org.jtester.module.JTesterException: No value found for property database.type
at org.jtester.tools.commons.ConfigHelper.getString(ConfigHelper.java:98)
at org.jtester.module.database.environment.DBEnvironmentFactory.getDBEnvironment(DBEnvironmentFactory.java:133)
at org.jtester.module.database.environment.DBEnvironmentFactory.getDefaultDBEnvironment(DBEnvironmentFactory.java:97)
at org.jtester.module.spring.strategy.JTesterBeanFactory.getMyBean(JTesterBeanFactory.java:74)
at org.jtester.module.spring.strategy.JTesterBeanFactory.getBean(JTesterBeanFactory.java:25)
at org.jtester.module.spring.strategy.JTesterBeanFactory.getProxyBean(JTesterBeanFactory.java:69)
at org.jtester.module.spring.strategy.JTesterBeanFactory.getBean(JTesterBeanFactory.java:59)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.jtester.module.spring.utility.SpringModuleHelper.newSpringContext(SpringModuleHelper.java:114)
at org.jtester.module.spring.utility.SpringModuleHelper.initSpringContext(SpringModuleHelper.java:87)
at org.jtester.module.spring.SpringModule$SpringTestListener.beforeClass(SpringModule.java:68)
at org.jtester.module.core.CoreModule$CoreModuleListener.beforeClass(CoreModule.java:114)
at org.jtester.module.core.utility.ListenerExecutor.executeBeforeClassEvents(ListenerExecutor.java:32)
at org.jtester.testng.JTesterCore.aBeforeClass(JTesterCore.java:35)

错误原因:
因为单元测试的数据库资源描述文件data-source-test.xml和正式的数据库资源data-source.xml里的beanid一致导致的

解决方案:
更改单元测试的数据库资源data-source-test.xml的bean id 为 dataSourceTest 问题结局

===============
还有一种可能是:
jtester.properties里没配置jtest需要用的值 以下几项:

#jtest use
database.type=mysql
database.url=jdbc:mysql://IP/**?useUnicode=true&characterEncoding=utf-8
database.userName=**
database.password=**
database.schemaNames=**
database.driverClassName=com.mysql.jdbc.Driver
database.maxActive=5
database.maxIdle=2
database.only.testdb.allowing=false

配置后就可以了。
如果运行的时候出现锁超时 是事务没配置 在data-source-test.xml里增加
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="mainDataSourceTest" />
</bean>

<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager" />
</bean>
即可

你可能感兴趣的:(database)