@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="/db-config-test.xml")
@TransactionConfiguration(defaultRollback=true,transactionManager="transactionManager")
public class MyTest{
@Autowired
private SessionFactory sessionFactory;
@Test
@Transactional
public void getStudent() {
Query query = sessionFactory.getCurrentSession().createQuery("from Student where id=:studentId");
query.setParameter("studentId", 1250L);
Student student= (Student) query.uniqueResult();
assertNotNull(student);
}
}
db-config-test.xml
<tx:annotation-driven />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.webapp.*</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="url" value="jdbc:oracle:thin:addressDB"/>
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="username" value="test" />
<property name="password" value="test" />
<property name="removeAbandoned" value="true"/>
<property name="initialSize" value="20" />
<property name="maxActive" value="30" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
Maven插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>MyTest.java</include>
</includes>
</configuration>
</plugin>
StackError:
通过IDE运行测试和在Maven中运行测试之间有一些不同:
@contextconfiguration
的多个Spring测试时,Spring上下文将被缓存并在测试之间共享。使用@dirtiescontext
避免所做的更改影响其他测试。在你的情况下,我猜这是上面的第一个要点。尝试为您的项目运行MVN dependency:Tree
,并确保将javax.validation
作为依赖项树的一部分。
我有一个带有Java配置类的Spring(4.2.5)项目。这些在正常运行项目时起作用,但我无法使我的测试工作。在下面的测试中,为空。 如果添加注释,则会出现异常 其中和在和中定义,后者是基于活动配置文件选择的。 [编辑2] 经过更多的搜索,我发现了这个问题,并且在检查了我的依赖项之后,我发现我在maven依赖项下有Spring-Core-4.1.9,而且我没有在我的POM中包含一个依赖项。添加依
我有根项目,然后是子模块。这些模块是相互依赖的,当我为一个模块运行maven测试时,它会抛出类未找到异常。 ProjectA --ProjectSubA --ProjectSubB --ProjectSubC(依赖项ProjectA和ProjectB) ProjectSubC有Maven测试,所以当它运行时,类在ProjectSubB和ProjectSubA中。现在如何解决这个问题。
我主要使用本教程为Maven配置Junit:http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html 我有一个测试类,当我执行“mvn测试”时,这个测试类被Maven捕获,但Maven没有检查它(结果应该是失败)。 我的测试类位于src/main/resources中(控制台显示“复制1个资源”): 我的P
我试图用内存中的H2 DB测试某些实体的持久性,但我认识到无论是在构建平台上运行还是在运行RunAs时,都不会按应有的方式被调用- 我可以肯定的是,序列是在H2 DB内部生成的。当我连接到这个生成的H2时,我甚至可以选择它们。所以这绝对不是H2内部的问题,而是Hibernate的问题。(通常Hibernate会在持久化需要ID的实体时自动分配ID)。 实体 引用实体中的引用。。。 持久性单位...
大家好,我实际上正在使用Jenkins和testlink(带有testlink插件)来实现测试自动化。 我谷歌了很多,但没有什么真正有用的,有人能帮我PLZ吗?
我正在为Junit编写测试,以测试我编写的删除函数: 此方法适用于同时具有前后节点的双链接列表。 问题是:我们的大学将针对我们编写的测试运行错误代码,以确定我们是否编写了足够的测试来捕获错误代码和异常。 我知道他们将运行的两个测试,但不知道错误的含义。 > 失败:缺少逻辑 故障:缺少NextNodeRepairLogic 这是我没有考虑的两个测试,因为我无法理解这些错误的含义。有人知道这些错误可能